Rishikesh Kumar Rishi has Published 1162 Articles

How to plot a line graph from histogram data in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 12:19:44

7K+ Views

To plot a line graph from histogram data in matplotlib, we use numpy histogram method to compute the histogram of a set of data.StepsAdd a subplot to the current figure, nrows=2, ncols=1 and index=1.Use numpy histogram method to get the histogram of a set of data.Plot the histogram using hist() method ... Read More

How to plot a multi-colored line, like a rainbow using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

2K+ Views

To plot multi-colored lines, like a rainbow, we can create a list of seven rainbow colors (VIBGYOR).StepsCreate x for data points using numpy.Create a list of colors (rainbow VIBGYOR).Iterate in the range of colors list length.Plot lines with x and y(x+i/20) using plot() method, with marker=o, linewidth=7 and colors[i] where i is the index.To display ... Read More

How to remove the label on the left side in matplotlib.pyplot pie charts?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

2K+ Views

To remove the label on the left side in a matplotlib pie chart, we can take the following steps −Create lists of hours, activities, and colors.Plot a pie chart using pie() method.To hide the label on the left side in matplotlib, we can use plt.ylabel("") with ablank string.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] ... Read More

How can I display text over columns in a bar chart in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 11:59:47

3K+ Views

To display text over columns in a bar chart, we can use text() method so that we could place text at a specific location (x and y) of the bars column.StepsCreate lists for x, y and percentage.Make a bar plot using bar() method.Iterate zipped x, y and percentage to place text for the ... Read More

How to handle an asymptote/discontinuity with Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 11-May-2021 11:48:28

928 Views

To handle an asymptote/discontinuity with matplotlib, we can take the following steps −Create x and y data points using numpy.Turn off the axes plot.Plot the line with x and y data points.Add a horizontal line across the axis, x=0.Add a vertical line across the axis, y=0.Place legend for the curve ... Read More

What is the preferred way to set Matplotlib figure/axes properties?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:51:09

279 Views

To set the properties of a plot, we can get the current axis of the plot. After that, we can perform several set_* methods to set the properties of the plot.StepsCreate a figure and a set of subplots using subplots() method with figsize=(5, 5).Create x and y data points using numpy.Plot x ... Read More

How to show multiple images in one figure in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:50:21

7K+ Views

To show multiple images in one figure in matplotlib, 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 current figure, ... Read More

How to remove gaps between bars in Matplotlib bar chart?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:47:45

8K+ Views

To remove gaps between bars, we can change the align value to center in the argument of bar() method.StepsCreate a dictionary called data with two keys, milk and water.Get the list of keys and values in the dictionay.Using subplots() method, create a figure and add a set of two subplots.On ... Read More

Rotate theta=0 on a Matplotlib polar plot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:47:22

1K+ Views

To set theta=0 on a matplotlib polar plot, we can take the following steps −Create random theta in the range of 0 to 100; convert them into radian.Using set_theta_zero_location() method, we can set the location of theta to 0.Plot theta_in_rad and data_r using plot() method.Set the title of the plot using title() ... Read More

What is the difference between plt.close() and plt.clf() in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

1K+ Views

plt.figure() - Create a new figure or activate an existing figure.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 figure number numclose(name), where name is a string, closes the figure with that labelclose('all') closes all the figure windowsplt.figure().clear() ... Read More

Advertisements