Menu Close

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

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.

Posted in Python, Python Answers