Tutorial Example

Fix Matplotlib plt.savefig() Save a Blank image – Matplotlib Tutorial

We often use plt.savefig() to save a plot to an image. However, we may find the saved image may be blank. In this tutorial, we will introduce you how to fix this problem.

For example, we often save an image in matplot as follows:

plt.show()
plt.savefig("imdb.svg", format = "svg")

Then, we may find imdb.svg may be a blank image.

How to fix?

We should save plot to an image before showing it.

plt.savefig("imdb.svg", format = "svg")
plt.show()

Run this code, we will find this problem is fixed.