Categories
Python Answers

How to save plot to image file instead of displaying it using Python Matplotlib?

Spread the love

Sometimes, we want to save plot to image file instead of displaying it using Python Matplotlib.

In this article, we’ll look at how to save plot to image file instead of displaying it using Python Matplotlib.

How to save plot to image file instead of displaying it using Python Matplotlib?

To save plot to image file instead of displaying it using Python Matplotlib, we can use the savefig method.

For instance, we write

from matplotlib import pyplot as plt

plt.savefig('foo.png')

to call savefig to save the plot to foo.png.

Conclusion

To save plot to image file instead of displaying it using Python Matplotlib, we can use the savefig method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *