Rishikesh Kumar Rishi has Published 1162 Articles

How to adjust the size of a Matplotlib legend box?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:52:48

6K+ Views

To adjust the size of a matplotlib legend box, we can use borderpad arguments in the legend method.StepsCreate line1 and line2 using two lists with different line widths.To place a legend on the figure and to adjust the size of legend box, use borderpad=2 in legend() method.To display the figure, use show() method.Examplefrom matplotlib import ... Read More

How to decrease the density of tick labels in subplots in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:51:13

815 Views

To decrease the density of tick labels in subplots in matplotlib, we can assign the minimum value to density.StepsInitialize a variable, density.Create x and y data points using numpy.Plot x and y data points using plot() method.Get or set the current tick locations and labels of the X-axis using xticks() method.To display the figure, ... Read More

How to switch axes in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:49:46

6K+ Views

To switch axes in matplotlib, we can create a figure and add two subplots using subplots() method. Plot curves, extract x and y data, and set these data in a second plotted curve.StepsCreate x and y data points using numpy.Create a figure and add a set of two subplots.Set the ... Read More

Place text inside a circle in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:47:57

2K+ Views

To place text inside a circle in matplotlib, we can take the following steps −Create a new figure or activate an existing figure using figure() method.Add a subplot method to the current axis.Create a Circle instance using Circle() class.Add a circle path on the plot.To place the text in the circle, we can use text() method.Scale ... Read More

How to reshape a networkx graph in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:45:40

311 Views

To reshape a networkx graph in Python, we can take the following steps −Create a data frame using Panda's data frame.Return a graph from Pandas DataFrame containing an edge list using from_pandas_edgelist() method.Draw the graph G with matplotlib. We can reshape the network by increasing and decreasing the list of keys "from" ... Read More

Plot a circle inside a rectangle in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:44:02

1K+ Views

To place a circle inside a rectangle, we can take the following steps −Create a new figure or activate an existing figure using figure() method.Add a subplot to the current axis.Create a rectangle and a circle instance.Add a rectangle patch to the current axis.Add a circle patch to the current axis.Scale x and ... Read More

How to plot and work with NaN values in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:42:04

840 Views

To plot and work with NaN values in matplotlib, we can take the following steps −Create data using numpy with some NaN values.Use imshow() method to display data as an image, i.e., on a 2D regular raster, with a colormap and data (from step 1).To display the figure, use show() method.Exampleimport ... Read More

How to display print statements interlaced with Matplotlib plots inline in iPython?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:40:28

309 Views

To display print statements interlaced with matplotlib plots inline in iPython, we can take the following steps.StepsImport pyplot from matplotlib.Make a list of data for hist plots.Initialize a variable "i" to use in print statement.Iterate the list of data (Step 2).Create a figure and a set of subplots using subplots() method.Place print statement.Plot ... Read More

How to remove relative shift in Matplotlib axis?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:38:34

1K+ Views

To remove relative shift in matplotlib axis, we can take the following steps −Plot a line with two input lists.Using gca() method, get the current axis and then return the X-axis instance. Get the formatter of the major ticker. To remove the relative shift, use set_useOffset(False) method.To display the figure, use show() method.Examplefrom ... Read More

Define the size of a grid on a plot using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 12-May-2021 11:36:34

5K+ Views

To define the size of a grid on a plot, we can take the following steps −Create a new figure or activate an existing figure using figure() method.Add an axes to the figure as a part of a subplot arrangement.Plot a curve with an input list.Make x and y margins ... Read More

Advertisements