Found 1034 Articles for Matplotlib

How to get boxplot data for Matplotlib boxplots?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:42:51

3K+ Views

To get boxplot data for Matplotlib boxplot we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make data frame using pandas.Make a box plot from DataFrame columns.Get boxplot's outliers, boxes, medians and whiskers data.Prit all the above information.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(age=[23, 45, 21, 15, 12])) _, bp = pd.DataFrame.boxplot(df, return_type='both') outliers = [flier.get_ydata() for flier in bp["fliers"]] boxes = [box.get_ydata() for box in ... Read More

Draw a parametrized curve using pyplot.plot() in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:25:18

3K+ Views

To draw a parametrized curve using pyplot.plot(), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of samples.Create t, r, x and y data points using numpy.Create a figure and a set of subplots.Use plot() method to plot x and y data points.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 400 t = np.linspace(0, 2 * np.pi, N) r = 0.5 + np.cos(t) x, y = r * ... Read More

Plotting grids across the subplots in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:41:00

6K+ Views

To plot grids across the subplots in Python Matplotlib, we can create multiple subplots and set the spine visibility false out of multiple axes.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Add a subplot to the current figure and set its spine visibility as false.Turn off the a☓3 labels.Share the X-axis accordingly.Configure the grid lines for a☓1, a☓2 and a☓3.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2) = plt.subplots(nrows=2) ax3 = fig.add_subplot(111, zorder=-1) ... Read More

How to set different opacity of edgecolor and facecolor of a patch in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:28:30

4K+ Views

To set different opacity of edge and face color, we can use a color tuple and the 4th index of the tuple could set the opacity value of the colors.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Set different values for edge and face color opacity.Add a rectangel patch using add_patch() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True figure, ax = plt.subplots() edge_color_opacity = 1 # 0Read More

How do I plot a spectrogram the same way that pylab's specgram() does? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:22:41

349 Views

To plot a spectrogram the same way that pylab's specgram() does, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create t, s1, s2, nse, x, NEFT and Fs data points using numpy.Create a new figure or activate an existing figure using subplots() method with nrows=2.Plot t and x data points using plot() method.Lay out a grid in current line style.Set the X-axis margins.Plot a spectrogram using specgram() method.Lay out a grid in current line style with dotted linestyle and some other properties.To display the figure, use show() method.Exampleimport matplotlib.pyplot as ... Read More

Adding a line to a scatter plot using Python's Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:11:11

15K+ Views

To add a line to a scatter plot using Python's Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, n, for number of data points.Plot x and y data points using scatter() method.Plot a line using plot() method.Limt the X-axis using xlim() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True n = 100 x = np.random.rand(n) y = np.random.rand(n) plt.scatter(x, y, c=x) plt.plot([0.1, 0.4, 0.3, 0.2]) plt.xlim(0, 1) ... Read More

How to disable the keyboard shortcuts in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:10:54

447 Views

To disable the keyboard shortcuts in Matplotlib, we can use remove('s') method.StepsSet the figure size and adjust the padding between and around the subplots.To disable the shortcut "s" to save the figure, use remove("s") method.Initialize a variable n for number of data points.Create x and y data points using numpyPlot x and y data points using plot() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rcParams['keymap.save'].remove('s') n = 10 x = np.random.rand(n) y = np.random.rand(n) plt.plot(x, y) plt.show()OutputRead More

How to plot categorical variables in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:16:54

4K+ Views

To plot categorical variables in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dictionary with some details.Extract the keys and values from the dictionary (Step 2).Create a figure and a set of subplots.Plot bar, scatter and plot with names and values data.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = {'apple': 10, 'orange': 15, 'lemon': 5} names = list(data.keys()) values = list(data.values()) fig, axs = plt.subplots(1, 3) axs[0].bar(names, values) axs[1].scatter(names, values) axs[2].plot(names, values) ... Read More

How do I change the font size of the scale in Matplotlib plots?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:17:35

8K+ Views

To change the font size of the scale in Matplotlib, we can use labelsize in the tick_params() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot x data points using plot() method.To change the font size of the scale in matplotlib, we can use labelsize in the ticks_params()method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.random.rand(10) ax.plot(x) ax.tick_params(axis='x', labelsize=20) plt.show()OutputRead More

How to save an array as a grayscale image with Matplotlib/Numpy?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:17:54

3K+ Views

To save an array as a grayscale image with Matplotlib/numpy, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data with 5☓5 dimension.Set the colormap to "gray".Plot the data using imshow() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True arr = np.random.rand(5, 5) plt.gray() plt.imshow(arr) plt.show()Output

Advertisements