Rishikesh Kumar Rishi has Published 1156 Articles

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

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

400 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

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

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

Getting information for bins in Matplotlib histogram function

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 13:52:52

809 Views

To get information for bins in matplotlib histogram function, we can take the following steps −Create a list of numbers for data and bins.Compute the histogram of a set of data using histogram() method.Get the hist and edges from the histogram (step 2).Find the frequency in a histogram.Make a bar with bins (Step 1) ... Read More

How to adjust the space between legend markers and labels in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 13:50:36

4K+ Views

To adjust the space between legend markers and labels, we can use labelspacing in legend method.StepsPlot lines with label1, label2 and label3.Initialize a space variable to increase or decrease the space between legend markers and label.Use legend method with labelspacing in the arguments.To display the figure, use show() method.Examplefrom matplotlib import pyplot as ... Read More

How to redefine a color for a specific value in a Matplotlib colormap?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 13:48:14

3K+ Views

To redefine a color for a specific value in matplotlib colormap, we can take the following steps −Get a colormap instance, defaulting to rc values if *name* is None using get_cmap() method, with gray colormap.Set the color for low out-of-range values when "norm.clip = False" using set_under() method.Using imshow() method, display ... Read More

Animate a rotating 3D graph in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 13:41:04

2K+ Views

To make a rotating 3D graph in matplotlib, we can use Animation class for calling a function repeatedly.StepsInitialize variables for number of mesh grids, frequency per second to call a function, frame numbers.Create x, y, and z array for a curve.Make a function to make z array using lambda function.To pass ... Read More

How to plot two Seaborn lmplots side-by-side (Matplotlib)?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 13:35:10

11K+ Views

To plot two graphs side-by-side in Seaborn, we can take the following steps −To create two graphs, we can use nrows=1, ncols=2 with figure size (7, 7).Create a data frame with keys, col1 and col2, using Pandas.Use countplot() to show the counts of observations in each categorical bin using bars.Adjust the padding ... Read More

Advertisements