- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
640 Views
To write numerical values on the plot, we can take the following steps −Create points for x and y using numpy.Create labels using xpoints.Use the scatter() method to scatter the points.Iterate labels, xpoints and ypoints and annotate the plot with label, x and y with different properties.To display the figure, use the 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 xpoints = np.linspace(1, 10, 25) ypoints = np.random.rand(25) labels = ["%.2f" % i for i in xpoints] plt.scatter(xpoints, ypoints, c=xpoints) for label, x, y in zip(labels, xpoints, ypoints): plt.annotate( ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
228 Views
To change the color of a line using radiobutton we can take following steps −Create x and y data points using numpy.Adjust the figure size and padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Plot curve with x and y data points using plot() method.Add an axes to the current figure and make it the current axes, using axes() method.Add a radio button to the current axes.Change the color of the curve with radion button using change_color() method, that can be passed in on_clicked() method.To display the figure use show() method.Exampleimport numpy as ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To zoom a portion of an image and insert in the same plot, we can take the following steps −Create x and y points, using numpy.To zoom a part of an image, we can make data for x and y points, in that range.Plot x and y points (Step 1), using the plot() method with lw=2, color red and label.Use the legend() method to place text for the plot, Main curve.Create the axes using the axes() method by putting the rectangle’s coordinate.Plot x and y points (Step 2), using the plot() method with lw=1, color='green' and label, i.e., subpart of ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
12K+ Views
To add extra ticks in matplotlib, we can take the following Steps −Create x and y points using numpy.Plot x and y points over the plot, where x ticks could be from 1 to 10 (100 data points) on the curve.To add extra ticks, use xticks() method and increase the range of ticks to 1 to 20 from 1 to 10.To display the figure, use the 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 x = np.linspace(1, 10, 100) y = np.sin(x) plt.plot(x, y) plt.xticks(range(1, 20)) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To plot multiple Seaborn jointplot, we can use the jointplot() method.StepsAdd a subplot to the current figure.Create a dictionary, with some keys.Create a dataframe using Pandas.Make a jointplot using the jointplot() method.To plot the curves, use the plot() method.To display the figure, use the show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.subplot() d = { 'y=1/x': [1 / i for i in range(1, 10)], 'y=x': [i for i in range(1, 10)], 'y=x^2': [i * i for i in range(1, 10)], 'y=x^3': [i ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To make the marker face color transparent without making the line transparent in matplotlib, we can take the following steps −Create x_data and y_data(sin(x_data)), using numpy.Plot curve using x_data and y_data, with marker style and marker size. By changing the alpha, we can make it transparent to opaque.To get the essence of transparency (keeping alhpa value lesser), we can make grid lines, to see through.To display the figure, use the 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 x_data = np.linspace(1, 10, 100) y_data = np.sin(x_data) plt.plot(x_data, y_data, c='green', marker='o', alpha=.3, ms=10, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
769 Views
To extract a subset of a colormap as a new colormap, we can take the following steps −Create a random array with 10×10 shape.Add a subplot to the current figure, where nrows=1, ncols=2 and index=1.Initialize using get_cmap so that scatter knows.Using imshow() method with colormap, display the data as an image, i.e., on a 2D regular raster, with data and colormap (Steps 1 and 3).Add a subplot to the current figure, where nrows=1, ncols=2 and index=2.Extract a subset of the colormap from the existing colormap (From step 3).Using imshow() method with colormap, display the data as an image, i.e., on a 2D regular raster, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To define a discrete colormap for imshow in matplotlib, we can take following the steps −Create data using numpy.Initialize the data using get_cmap, so that scatter knows.Using imshow() method with colormap, display the data as an image, i.e., on a 2D regular raster.Create the colorbar using the colorbar() method.To display the figure, use the show() method.Exampleimport numpy as np from matplotlib import pyplot as plt import matplotlib plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(10, 10) cmap = matplotlib.cm.get_cmap('Paired_r', 10) plt.imshow(data, cmap=cmap) plt.colorbar() plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
599 Views
To enforce axis range in matplotlib, we can take the following steps −Set x and y limits using xlim and ylim methods, respectively.Create x and y points for the curve using numpy.Plot x and y using the plot() method.To show the figure, use the show() method.Exampleimport matplotlib.pyplot as plt import datetime import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([datetime.datetime(2021, 1, 1, i, 0) for i in range(24)]) y = np.random.randint(100, size=x.shape) plt.plot(x, y) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To plot a time series in Python using matplotlib, we can take the following steps −Create x and y points, using numpy.Plot the created x and y points using the plot() method.To display the figure, use the show() method.Exampleimport matplotlib.pyplot as plt import datetime import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([datetime.datetime(2021, 1, 1, i, 0) for i in range(24)]) y = np.random.randint(100, size=x.shape) plt.plot(x, y) plt.show()Output