- 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)
37K+ Views
To create line segments between two points in matplotlib, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.To make two points, create two lists.Extract x and y values from point1 and point2.Plot x and y values using plot() method.Place text for both the points.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 point1 = [1, 2] point2 = [3, 4] x_values = [point1[0], point2[0]] y_values = [point1[1], point2[1]] plt.plot(x_values, y_values, 'bo', linestyle="--") plt.text(point1[0]-0.015, point1[1]+0.25, "Point1") plt.text(point2[0]-0.050, point2[1]-0.25, "Point2") plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
375 Views
RendererFile typesDescriptionAGGPngRaster graphics − high-quality images using the Anti-Grain Geometry engineCairopng, ps, pdf, svgRaster or vector graphics − using the Cairo libraryStepsSet the figure size and adjust the padding between and around the subplots.Set the backend name as "Agg".Create a 5☓5 matrix array using numpy.Use imshow() method to display data as an image, i.e., on a 2D regular raster.To save the figure, use savefig() method.Exampleimport matplotlib as mpl import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True mpl.use("Agg") data = np.random.rand(5, 5) plt.imshow(data, interpolation='nearest', cmap="copper") plt.savefig('agg.png')OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To find the area between two curves plot in matplotlib, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create x, c1 and c2 data points using numpy.Plot (x, c1) and (x, c2) using plot() methods.Fill the area between the two curves, c1 and c2, with grey color and hatch "|", using fill_between() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 1, 100) c1 = x ** 2 c2 = x plt.plot(x, c1) plt.plot(x, c2) plt.fill_between(x, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
846 Views
To make the Parula colormap in matplotlib, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create colormap data using numpy.Create a 'LinearSegmentedColormap' from a list of colors.Viscum is a little tool for analyzing colormaps and creating new colormaps.Use imshow() method to display data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Examplefrom matplotlib.colors import LinearSegmentedColormap import matplotlib.pyplot as plt import numpy as np from viscm import viscm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True cm_data = np.random.rand(4, 4) parula_map = LinearSegmentedColormap.from_list('parula', cm_data) viscm(parula_map) plt.imshow(np.linspace(0, 100, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To set the size of the plotting canvas in matplotlib, we can take the following steps:Set the figure size and adjust the padding between and around the subplots. Use figsize 7.50 and 3.50 to set the figure size.Create x and y data points using numpy.Plot 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 x = np.linspace(-2, 2, 100) y = np.sin(x) plt.plot(x, y) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
259 Views
To get the default Seaborn color palette, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Return a list of colors or continuous colormap defining a palette.Plot the values in a color palette as a horizontal array.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True current_palette = sns.color_palette() sns.palplot(current_palette) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To add different font sizes in the same annotation method, we can take the following stepsMake lists of x and y data points where text could be placed.Initialize a variable 'labels', i.e., a string.Make a list of sizes of the fonts.Use subplots() method to create a figure and a set of subplots.Iterate above lists and annotate each label's text and set its fontsize.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 X = [0.1, .2, .3, .4, .5, .6, 0.8] Y = [0.1, 0.12, 0.13, 0.20, 0.23, 0.25, 0.27] labels = 'Welcome' ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To load an image and show the image using Keras, we will use load_image() method to load an image and set the target size of the image to be shown.StepsUse load_img() method to load the figure.Set the target size of the image.To display the figure, use show() method.Examplefrom keras.preprocessing import image img = image.load_img('bird.jpg', target_size=(350, 750)) img.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To adjust the spacing between the edge of the plot and the X-axis, we can use tight_layout() method or set the bottom padding of the current figure.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using plot() method.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 x = np.linspace(-2, 2, 100) y = np.exp(x) plt.plot(x, y, c='red', lw=1) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To add footnote under the X-axis using matplotlib, we can use figtext() and text() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using numpy.To place the footnote, use figtext() method with x, y position and box properties.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 x = np.linspace(-2, 2, 100) y = np.exp(x) plt.plot(x, y) plt.figtext(0.5, 0.01, "footnote: $y=e^{x}$", ha="center", fontsize=18, bbox={"facecolor": "green", "alpha": 0.75, "pad": 5}) plt.show()OutputRead More