Rishikesh Kumar Rishi has Published 1162 Articles

How to show two figures using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 11:06:50

8K+ Views

We can use the method, plt.figure(), to create the figures, and then, set their titles by passing strings as arguments.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Draw a line using plot() method, over the current figure.Create a new figure, or activate ... Read More

Plotting a 3d cube, a sphere and a vector in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 11:06:14

4K+ Views

Get fig from plt.figure() and create three different axes using add_subplot, where projection=3d.Set up the figure title using ax.set_title("name of the figure"). Use the method ax.quiver to plot vector projection, plot3D for cube, and plot_wireframe for sphere after using sin and cos.StepsCreate a new figure, or activate an existing figure.To ... Read More

Changing the color of an axis in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 11:02:31

7K+ Views

First, we can get the axes. Then, ax.spines could help to set the color by specifying the name of the axes, i.e., top, bottom, right and left.StepsAdd an axes to the current figure and make it the current axes.Using step 1 axes, we can set the color of all the ... Read More

How to have logarithmic bins in a Python histogram?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 11:01:55

4K+ Views

We can set the logarithmic bins while plotting histogram using plt.hist(bin="").StepsCreate an array x, where range is 100.Plot a histogram using plt.hist() method. We can pass logarithmic bins using logarithmic bins that returns numbers spaced evenly on a log scale.Get the current axes, creating one if necessary and set the ... Read More

Plot width settings in ipython notebook

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 11:01:37

519 Views

Using plt.rcParams["figure.figsize"], we can get the width setting.StepsTo get the plot width setting, use plt.rcParams["figure.figsize"] statement.Override the plt.rcParams["figure.figsize"] with a tuple (12, 9).After updating the width, get the updated width using plt.rcParams["figure.figsize"].ExamplesIn IDEExampleimport matplotlib.pyplot as plt print("Before, plot width setting:", plt.rcParams["figure.figsize"]) plt.rcParams["figure.figsize"] = (12, 9) print("Before, plot width setting:", plt.rcParams["figure.figsize"])OutputBefore, ... Read More

Setting Different Bar color in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 10:56:01

12K+ Views

We can first create bars and then, by using set_color, we can set the color of the bars.StepsPass two lists consisting of four elements, into the bars method argument.Step 1 returns bars.Return values (0, 1, 2, 3) can be set with different colors, using set_color() method. Green, Black, Red color ... Read More

How to animate a scatter plot in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 10:54:57

5K+ Views

Using the FuncAnimation method of matplotlib, we can animate the diagram. We can pass a user defined method where we will be changing the position of the particles, and at the end, we will return plot type.StepsGet the particle's initial position, velocity, force, and size.Create a new figure, or activate ... Read More

How to set the current figure in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 10:54:16

628 Views

Using the figure() method, we can set the current figure.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Create a new figure, or activate an existing figure, with the window title “Welcome to figure 2”.Using plt.show(), show the figures.Examplefrom matplotlib import pyplot as ... Read More

How to remove lines in a Matplotlib plot?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 10:50:44

6K+ Views

We will create two lines, i.e., line1 and line2. After that, we will pop the second line and will remove it.StepsCreate lists for line1 and line2.Plot line1 and line 2 using plot() method, line 2 with style =’dashed’.Set or retrieve auto-scaling margins(0.2).Pop line 2, and remove it using remove() method.The ... Read More

Python xticks in subplots

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 10:50:15

4K+ Views

Subplot can split the figure in nrow*ncols parts and plt.xticks could help to plot the xticks for subplots.StepsCreate two lists for line 1 and line 2.Add a subplot to the current figure, nrow = 1, ncols = 2 and index = 1.Draw line 1 with style as dashed.Set or retrieve ... Read More

Advertisements