Rishikesh Kumar Rishi has Published 1162 Articles

Drawing a rectangle with only border in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:02:39

3K+ Views

To draw a rectangle with only border in matplotlib, we can take the following steps−Create a figure and a set of subplots.Get the current axes, creating one if necessary.Add a patch, i.e., a rectangle to the current axes that is returned in step 2. Set the facecolor attribute to 'none'.To ... Read More

How to insert a small image on the corner of a plot with Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:02:09

7K+ Views

To insert a small image on the corner of a plot with matplotlib, we can take the following steps−Read an image from a file into an array using imread() method.Using subplots() method, create a figure and add a set of subplots.Plot a line on the current axis.Create newax (new axis) ... Read More

How to suppress Matplotlib warning?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:01:45

3K+ Views

Let's take an example. We create a set of data points such that it would generate some warnings. We will create data points x from −1 to 1 and try to find log in that range, which means it will throw an error at value 0, while calculating logs.StepsCreate data ... Read More

Plot a circle with an edgecolor and hatch in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:01:13

356 Views

To place edge color and hatch of 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 with an edgecolor, hatch and linewidth of the edge.Add a circle path ... Read More

How to fill color above the curve in Matplotlib Program?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:00:35

2K+ Views

To fill color above the curve, we can take the following steps −StepsInitialize the variable n. Initialize x and y data points using numpy.Create a figure and a set of subplots, fig and ax.Plot the curve using plot() method.Using fill_between() method, fill the area between two curves, with 1 value.To display the figure, use ... Read More

How to create a stacked bar chart for my DataFrame using Seaborn in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:00:15

1K+ Views

To create a stacked bar chart, we can use Seaborn's barplot() method, i.e., show point estimates and confidence intervals with bars.Create df using Pandas Data Frame.Using barplot() method, create bar_plot1 and bar_plot2 with color as red and green, and label as count and select.To enable legend, use legend() method, at the upper-right location.To display ... Read More

Plot a histogram with colors taken from colormap in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:59:54

1K+ Views

To plot a histogram with colors taken from colormap, we can use the setp() method.StepsCreate data points using numpy.Plot data (Step 1) using hist() method, with bins=25, rwidth=.75, ...etc.Returned values n, bins and patches can help to find col.Get a colormap instance for name "RdYlBu".Zip the col and patches.Now, using setp() method, set ... Read More

Matplotlib figure to image as a numpy array

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:59:03

3K+ Views

We can use the following steps to convert a figure into a numpy array −Read a figure from a directory; convert it into numpy array.Use imshow() method to display the image.Use show() method to display it.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True im = ... Read More

Auto adjust font size in Seaborn heatmap using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:58:28

2K+ Views

To adjust font size in Seaborn, we can take followig steps−Create a dictionary with some mathematical expressionsCreate a dataframe using Pandas data frame.Create a heatmap using heatmap() method.To adjust the font size in Seaborn heatmap, change the fontsize value.To display the figure, use show() method.Exampleimport numpy as np import seaborn ... Read More

Drawing multiple figures in parallel in Python with Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:57:56

803 Views

To draw multiple figures in parallel in Python with matplolib, we can take the following steps−Create random data using numpy.Add a subplot to the current figure, nrows=1, ncols=4 and at index=1.Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="Blues_r".Add a subplot to the ... Read More

Advertisements