Categories
Python Answers

How to fix Matplotlib savefig outputs blank image with Python?

Spread the love

Sometimes, we want to fix Matplotlib savefig outputs blank image with Python.

In this article, we’ll look at how to fix Matplotlib savefig outputs blank image with Python.

How to fix Matplotlib savefig outputs blank image with Python?

To fix Matplotlib savefig outputs blank image with Python, we call gcf and show before we call savefig.

For instance, we write

fig1 = plt.gcf()
plt.show()
plt.draw()
fig1.savefig('test.png', dpi=100)

to call gcf to get the current figure and save it.

Then we call show

And then we save the figure saved by calling gcf by calling savefig with the file name.

Conclusion

To fix Matplotlib savefig outputs blank image with Python, we call gcf and show before we call savefig.

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 *