Center Labels in a Matplotlib Histogram Plot

Rishikesh Kumar Rishi
Updated on 01-Jun-2021 11:33:02

7K+ Views

To place the labels at the center in a histogram plot, we can calculate the mid-point of each patch and place the ticklabels accordinly using xticks() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a random standard sample data, x.Initialize a variable for number of bins.Use hist() method to make a histogram plot.Calculate the list of ticks at the center of each patch.Make a list of tickslabels.Use xticks() method to place xticks and labels.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

Extract Data from a Matplotlib Plot

Rishikesh Kumar Rishi
Updated on 01-Jun-2021 11:32:47

16K+ Views

To extract data from a plot in matplotlib, we can use get_xdata() and get_ydata() methods.StepsSet the figure size and adjust the padding between and around the subplots.Create y data points using numpy.Plot y data points with color=red and linewidth=5.Print a statment for data extraction.Use get_xdata() and get_ydata() methods to extract the data from the plot (step 3).Print x and y data (Step 5).To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True y = np.array([1, 3, 2, 5, 2, 3, 1]) curve, = plt.plot(y, c='red', lw=5) print("Extracting ... Read More

Show Tick Labels When Sharing an Axis in Matplotlib

Rishikesh Kumar Rishi
Updated on 01-Jun-2021 11:31:06

953 Views

To show the tick labels when sharing an axis, we can just use the subplot() method with sharey argument. By default, y ticklabels could be visible.StepsSet the figure size and adjust the padding between and around the subplots.Add a subplot to the current figure using subplot() method, where nrows=1, ncols=2 and index=1 for axis ax1.Plot a line on the axis 1.Add a subplot to the current figure, using subplot() method, where nrows=1, ncols=2 and index=2 for axis ax2.Plot a line on the axis 2.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] ... Read More

Plot Complex Numbers on Argand Diagram using Matplotlib

Rishikesh Kumar Rishi
Updated on 01-Jun-2021 11:22:41

708 Views

To plot complex numbers using matplotlib, we can make a dataset with complex numbers.StepsSet the figure size and adjust the padding between and around the subplots.Create random complex numbers.Create a figure and a set of subplots using subplots() method.Plot the scatter points using scatter() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(10) + 1j*np.random.rand(10) fig, ax = plt.subplots() ax.scatter(data.real, data.imag, c=data.real, cmap="RdYlBu_r") plt.show()OutputRead More

Plot Multiple Line Graphs Using Pandas and Matplotlib

Rishikesh Kumar Rishi
Updated on 01-Jun-2021 11:22:03

4K+ Views

To plot multiple line graphs using Pandas and Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a 2D potentially heterogeneous tabular data using Pandas DataFrame class, where the column are x, y and equation.Get the reshaped dataframe organized by the given index such as x, equation, and y.Use the plot() method to plot the lines.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame([    ["y=x^3", 0, 0],    ["y=x^3", 1, 1], ... Read More

Electrical Components and Their Symbols

Manish Kumar Saini
Updated on 31-May-2021 15:02:39

5K+ Views

Wires and TracesComponent NameSymbolWires or ConductorTrace Junction or Connected WiresTrace Crossing or Unconnected WiresGroundsComponent NameSymbolGround or EarthSignal GroundChassis GroundSourcesComponent NameSymbolSingle CellBattery (Combination of cells)Photovoltaic Cell (Solar Cell)Independent or Constant Voltage SourceControlled or Dependent Voltage SourceIndependent or Constant Current SourceControlled or Dependent Current SourceAC voltage SourceResistorsComponent NameSymbolFixed ResistorRheostat (Variable Resistor)PotentiometerThermistor or VaristorCapacitorsComponent NameSymbolNon-polarized CapacitorPolarized CapacitorVariable CapacitorTrimmer CapacitorInductorsComponent NameSymbolAir Cored InductorIron Cored InductorTapped InductorTransformersComponent NameSymbolTransformerCenter Tapped TransformerStep up TransformerStep Down TransformerTransformer with two secondary windingsCurrent TransformerPotential TransformerZero Sequence Current Transformer (ZSCT)DiodesComponent NameSymbolPN Junction DiodeSchottky DiodeZener DiodeLight Emitting Diode (LED)Photo DiodeTunnel DiodeVaricap (Variable Capacitor Diode)Schockley DiodeConstant Current DiodeSilicon Controlled Rectifier (SCR)DiacTransistorsComponent NameSymbolN-channel, Junction ... Read More

Interfacing an Ultrasonic Sensor with Arduino

Yash Sanghvi
Updated on 31-May-2021 15:01:09

4K+ Views

In this tutorial, we will interface the ultrasonic sensor HC-SR04 with the Arduino to get the distance from a surface in centimetres.Circuit DiagramAs you can see, you need to connect the Vcc pin of HC-SR04 to 5V, GND to GND, Trig pin to pin 7 of Arduino Uno, and Echo pin to pin 6 of Arduino. You can actually choose any GPIO instead of pins 7 and 6. You just have to make sure that the definitions in the code are proper.Working of HC-SR04The HC-SR04 emits ultrasonic waves at 40, 000 Hz. In order to make it emit waves, we ... Read More

Read a Specific Bit of a Number with Arduino

Yash Sanghvi
Updated on 31-May-2021 15:00:22

3K+ Views

Each number has a specific binary representation. For example, 8 can be represented as 0b1000, 15 can be represented as 0b1111, and so on. If you wish to read a specific bit of a number, Arduino has an inbuilt method for it.SyntaxbitRead(x, index)where, x is the number whose bits you are reading, index is the bit to read. 0 corresponds to least significant (right-most) bit, and so on.This function returns either 0 or 1 depending on the value of that bit in that number.ExampleThe following example will illustrate the use of this function −void setup() {    // put your setup ... Read More

Interfacing a Speaker with Arduino

Yash Sanghvi
Updated on 31-May-2021 14:59:20

1K+ Views

In this tutorial, we will interface a simple piezo-buzzer with Arduino to create beeping sounds. Such an arrangement can be used in applications like burglar alarms, or water level indicators or such similar projects.Circuit DiagramAs you can see, the circuit diagram is quite straightforward. You need to connect the buzzer’s GND to Arduino’s GND, and the other wire to one GPIO of the Arduino (we have chosen pin 7). You can optionally add a small resistor (~100 Ohm), between the GPIO and the buzzer.Code WalkthroughThe entire code is given below −#define buzzerPin 7               ... Read More

Getting Data from Temperature and Humidity Sensor using Arduino

Yash Sanghvi
Updated on 31-May-2021 14:58:55

639 Views

In this tutorial, we will interface Arduino DHT-22 Temperature and Humidity Sensor and print the obtained temperature and humidity values on the Serial Monitor.Circuit DiagramWhen the DHT-22 is facing you, the first pin from the left, the VCC pin is connected to 5V, the next pin is the DATA pin, and it is connected to pin 2 on Arduino Uno. The third pin is Not Connected. The 4th pin, GND, is connected to GND on Arduino. A 10K resistor is to be connected between the DATA pin and the Vcc pin of DHT22, as you can see in the above ... Read More

Advertisements