Rishikesh Kumar Rishi has Published 1156 Articles

Manually add legend Items Python Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 07:52:12

23K+ Views

Using plt.legend() method, we can create a legend, and passing frameon would help to keep the border over there.StepsSet the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Draw lines using plot() method.Location and legend drawn flags can help to find a location and make the flag True ... Read More

Show only certain items in legend Python Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 07:51:23

2K+ Views

Using plt.legend(), we can add or show certain items just by putting the values in the list.StepsSet the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Plot the lines using the lists that are passed in the plot() method argument.Location and legend_drawn flags can help to find a ... Read More

How to add a second X-axis in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 07:48:18

12K+ Views

We can use the twiny() method to create a second X-axis. Similarly, using twinx, we can create a shared Y-axis.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Plot line with lists passed in the argument of plot() method with color="red".Create a twin of Axes ... Read More

What does .shape[] do in “for i in range(Y.shape[0])” using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 07:45:39

1K+ Views

The shape property is usually used to get the current shape of an array, but it may also be used to reshape the array in-place by assigning a tuple of array dimensions to it.StepsGet an array Y using np.array method.Y.shape would return a tuple (4, ).Y.shape[0] method would return 4, ... Read More

Automatically run %matplotlib inline in IPython Notebook

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 16-Mar-2021 20:15:30

302 Views

%matplotlib would return the backend value.%matplotlib auto would return the name of the backend, over Ipython shell.ExampleIn [1]: %matplotlib autoOutputUsing matplotlib backend: GTK3Agg

How to show two figures using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

10K+ 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

5K+ 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

9K+ 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

Plot width settings in ipython notebook

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

655 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

17K+ 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

Advertisements