Rishikesh Kumar Rishi has Published 1156 Articles

How to add percentages on top of bars in Seaborn using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:33:49

7K+ Views

To add percentages on top of bars in Seaborn, we can take the following steps −Create the lists, x, y and percentages to plot using Seaborn.Using barplot, show point estimates and confidence intervals with bars. Store the returned axis.Find patches from the returned axis (In step 2).Iterate the patches (returned in ... Read More

How to decouple hatch and edge color in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:33:30

909 Views

To decouple hatch and edge color in matplotlib, we can use hatch color “o” and edge color “red”.−StepsCreate a new figure or activate existing figure.Add a subplot arrangement to the current axes.Create two lists of data points.Use bar() method with hatch and edgecolor.To display the figure, use show() method.Exampleimport matplotlib.pyplot ... Read More

How do I extend the margin at the bottom of a figure in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:28:47

766 Views

To fix the extension of margin at the bottom of a figure, we can take the following steps −Using Pandas dataframe, create a df with the keys, time and speed.Plot df.time and df.speed using plot() method.Tick_params() is a convenience method for changing the appearance of ticks and tick labels. rotation=90 extends the tick ... Read More

How can I set the background color on specific areas of a Pyplot figure using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:28:27

2K+ Views

To set the background color on specific areas of a pyplot, we can take the following steps −Using subplots() method, create a figure and a set of subplots, where nrows=1.Using rectangle, we can create a rectangle, defined via an anchor point and its width and height. Where, edgecolor=orange, linewidth=7, and ... Read More

How to set my xlabel at the end of X-axis in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:28:01

10K+ Views

To set the xlabel at the end of X-axis in matplotlib, we can take the following steps −Create data points for x using numpy.Using subplot() method, add a subplot to the current figure.Plot x and log(x) using plot() method.Set the label on X-axis using set_label() method, with fontsize=16, loc=left, and color=red.To set the xlabel at the end ... Read More

How to draw axis in the middle of a figure in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:27:41

4K+ Views

To draw axis in the middle of a figure, we can take the following steps −Create x and sqr data points using numpy.Create a new figure, or activate an existing figure, using figure() method.Add an axis to the figure as a part of a subplot arrangement.Set the postion of left and bottom ... Read More

What does a 4-element tuple argument for 'bbox_to_anchor' mean in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:27:08

475 Views

If a 4-tuple or B box Base is given, then it specifies the b box (x, y, width, height) that the legend is placed in.StepsCreate x and y data points using numpy.Plot x and y using plot() method, with label y=sin(x) and color=green.To place the legend at a specific location, ... Read More

How to make the angles in a Matplotlib polar plot go clockwise with 0° at the top?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:26:43

5K+ Views

To make the angles in a matplotlib polar plot go clockwise with 00 at the top, we can take the followingsteps−StepsAdd a subplot to the current figure ax.To set polar plot clockwise with top 0o, set the theta direction as −1 using set_theta_direction()method. And, use set_theta_offset() method to set the ... Read More

Matplotlib – Plot over an image background in Python

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:26:18

20K+ Views

To plot over an image background, we can take the following steps−Read an image from a file into an array.Create a figure (fig) and add a set of subplots (ax) with extent [0, 300, 0, 300].Create an array x of range (300).Plot x using plot() method with linestyle=dotted, linewidth=2, and ... Read More

Equivalent to matlab's imagesc in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:25:54

4K+ Views

To make equivalent imagesc, we can use extent [left, right, bottom, top].StepsCreate random data using numpy.Display the data as an image, i.e., on a 2D regular raster, with data and extent [−1, 1, −1, 1] arguments.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as ... Read More

Advertisements