
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1034 Articles for Matplotlib

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

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

8K+ Views
We can create a grid of subplots by using plt.subplot() or plt.subplots() methods in python Matplotlib . 'subplots' refers collection of multiple plots within a single figure, where each subplot is an axis object. We can create multiple subplots by seting the spine visibility false out of multiple axes. Plotting grids across subplots Steps involved to plot grids across the subplots are follows. Setting parameters for figure Creating ... Read More

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

472 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

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

635 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

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

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

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