- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to save an image with matplotlib.pyplot?
63 Lectures 6 hours
To save an image with matplotlib.pyplot.savefig(), we can take the following steps −
- 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 save the figure, use savefig() method.
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-np.pi, np.pi, 100) plt.plot(x, np.sin(x) * x, c='red') plt.savefig("myimage.png")
When we execute the code, it will save the following image as "myimage.png" in the Project directory.
- How to save an array as a grayscale image with Matplotlib/Numpy?
- How to save HTML Canvas as an Image with canvas.toDataURL()?
- How to save an Image in OpenCV using C++?
- How to save DIV as Image with HTM5 canvas to image with the extension?
- How to zoom subplots together in Matplotlib/Pyplot?
- How to save DIV as Image with canvas2image with extension in HTML?
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- Overlay an image segmentation with Numpy and Matplotlib
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to save Matplotlib 3d rotating plots?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How to plot an animated image matrix in matplotlib?
- Gaussian filtering an image with NaN in Python Matplotlib
- Drawing circles on an image with Matplotlib and NumPy
- How to show an image in Matplotlib in different colors with different channels?