Categories
Python Answers

How to removing white space around a saved image with Python matplotlib?

Spread the love

Sometimes, we want to removing white space around a saved image with Python matplotlib

In this article, we’ll look at how to removing white space around a saved image with Python matplotlib

How to removing white space around a saved image with Python matplotlib?

To removing white space around a saved image with Python matplotlib, we call plt.savefig with the bbox_inches argument set to 'tight'.

For instance, we write

plt.savefig('myfile.png', bbox_inches="tight")

to call savefig to save the flots to myfile.png.

We set bbox_inches to 'tight' to reduce padding between the plots.

Conclusion

To removing white space around a saved image with Python matplotlib, we call plt.savefig with the bbox_inches argument set to 'tight'.

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 *