Rishikesh Kumar Rishi has Published 1162 Articles

Plot a rectangle with an edgecolor in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

1K+ Views

To put edgecolor of a rectangle 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 rectangle instance using Rectangle() class with an edgecolor and linewidth of the edge.Add a rectangle path ... Read More

Centering x-tick labels between tick marks in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:17:52

708 Views

To place labels between two ticks, we can take the following steps−Load some sample data, r.Create a copy of the array, cast to a specified type.Create a figure and a set of subplots using subplots() method.Plot date and r sample data.Set the locator of the major/minor ticker using set_major_locator() and ... Read More

How to change a table's fontsize with matplotlib.pyplot?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:17:24

7K+ Views

To change a table's fontsize with matplotlib, we can use set_fontsize() method.StepsCreate a figure and a set of subplots, nrows=1 and ncols=1.Create random data using numpy.Create columns value.Make the axis tight and off.Initialize a variable fontsize to change the font size.Set the font size of the table using set_font_size() method.To ... Read More

Changing Matplotlib subplot size/position after axes creation

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:16:58

995 Views

To change subplot size or position after axes creation, we can take the following steps−Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.A grid layout to place subplots within a figure using GridSpec() ... Read More

How to rotate Matplotlib annotation to match a line?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 15-May-2021 12:16:25

3K+ Views

To rotate matplotlib annotation to match a line, we can take the following steps−Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.Initialize the variables, m (slope) and c (intercept).Create x and y data ... Read More

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

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

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

Advertisements