Rishikesh Kumar Rishi has Published 1156 Articles

How do I close all the open pyplot windows (Matplotlib)?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:15:48

11K+ Views

plt.figure().close(): Close a figure window.close() by itself closes the current figureclose(h), where h is a Figure instance, closes that figureclose(num) closes the figure with number=numclose(name), where name is a string, closes the figure with that labelclose('all') closes all the figure windowsExamplefrom matplotlib import pyplot as plt fig = plt.figure() ax ... Read More

Plotting a horizontal line on multiple subplots in Python using pyplot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:12:33

8K+ Views

To plot a horizontal line on multiple subplots in Python, we can use subplots to get multiple axes and axhline() method to draw a horizontal line.StepsCreate a figure and a set of subplots. Here, we will create 3 subplots.Use axhline() method to draw horizontal lines on each axis.To display the ... Read More

Overlay an image segmentation with Numpy and Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:12:02

2K+ Views

To overlay an image segmentation with numpy, we can take the following Steps −Make a masked array of 10×10 dimension.Update the masked array with 1 for some region.Make image data using numpy.Mask an array where a condition is met, to get the masked data.Create a new figure or activate an ... Read More

How to limit the number of groups shown in a Seaborn countplot using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:11:39

2K+ Views

To limit the number of groups shown in a Seaborn countplot, we can use a variable group_count, used in countplot() method arguments.StepsCreate a figure and two sets of subplots.Create a data frame using Pandas, with two keys.Initalize a variable group_count to limit the group count in countplot() method.Use countplot() method ... Read More

Plotting a probability density function by sample with Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:11:07

2K+ Views

To plot a probability density function by sample, we can use numpy for x and y data points.StepsCreate x and p data points using numpy.Plot x and p data points using plot() method.Scale X-axis in a range.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot ... Read More

How to plot a 2D matrix in Python with colorbar Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:10:48

8K+ Views

To plot a 2D matrix in Python with colorbar, we can use numpy to create a 2D array matrix and use that matrix in the imshow() method.StepsCreate data2D using numpy.Use imshow() method to display data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance ... Read More

How to retrieve colorbar instance from figure in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:10:26

712 Views

To retrieve colorbar instance from figure in matplotlib, we can use imshow scalar mappable object in colorbar to retrieve colorbar instance.StepsGet random data with 10×10 dimension of array, data points between -1 to 1.Use imshow() method to display data as an image, i.e., on a 2D regular raster.Create a colorbar ... Read More

Rotating axis text for each subplot in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:10:01

439 Views

To rotate axis text for each subplot, we can use text with rotation in the argument.StepsCreate a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.Adjust the subplot layout parameters using subplots_adjust() method.Add a centered title to the ... Read More

Layering a contourf plot and surface_plot in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:09:22

205 Views

To layer a contourf plot and surface_plot in matplotlib, we can take the following Steps −Initialize the variables, delta, xrange, yrange, x and y using numpy.Create a new figure or activate an existing figure using figure() method.Get the current axis where projection='3d'.Create a 3d countour plot with x and y ... Read More

How to make a heatmap square in Seaborn FacetGrid using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:08:59

696 Views

To make a heatmap square in Seaborn facetgrid, we cn use heatmap() method with 10×10 random data set.StepsCreate a random data of size 10×10, with minimum -1 and maximum 10.Plot rectangular data as a color-encoded matrix using heatmap() method with data and color map "twilight_r".To display the figure, use show() ... Read More

Advertisements