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
.