Rishikesh Kumar Rishi has Published 1156 Articles

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

370 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

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

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

How to add a variable to Python plt.title?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

12K+ Views

To add a varaible to Python plt.title(), we can take the following steps −Create data points for x and y using numpy and num (is a variable) to calculate y and set this in title.Plot x and y data points using plot() method with red color.Set the title of the curve with variable ... Read More

How to plot data from multiple two-column text files with legends in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:46:01

2K+ Views

To plot data from multiple two-column text files with legends in matplotlib, we can take the following steps −Import genfromtxt from pylab. It has several options to read data from a text file and plot the data.Read two text files,  test.txt and test1.txt (having two columns of data), using genfromtxt and store the data ... Read More

Hide Matplotlib descriptions in Jupyter notebook

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

2K+ Views

To hide matplotlib descriptions of an instance while calling plot() method, we can take the following steps −Open Ipython instance.import numpy as npfrom matplotlib, import pyplot as pltCreate points for x, i.e., np.linspace(1, 10, 1000)Now, plot the line using plot() method.To hide the instance, use plt.plot(x); i.e., (with semi-colon)Or, use _ ... Read More

Plot multiple columns of Pandas DataFrame using Seaborn

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

1K+ Views

To plot multiple columns of Pandas DataFrame using Seaborn, we can take the following steps −Make a dataframe using Pandas.Plot a bar using Seaborn's barplot() method.Rotate the xticks label by 45 angle.To display the figure, use show() method.Exampleimport pandas import matplotlib.pylab as plt import seaborn as sns import numpy as np ... Read More

Setting different error bar colors in barplot in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:44:43

1K+ Views

To set different error bar colors in barplot in matplotlib, we can take the following steps −Create a figure and add a set of subplots using subplots() method.Make a barplot with data range 4, heights 2. yerr means vertical errorbars to the bar tips. The values are sizes relative to the ... Read More

Advertisements