Why is my plt.savefig is not working?

Solution 1:

When you close the image displayed by plt.show(), the image is closed and freed from memory.

You should call savefig and savetxt before calling show.

Solution 2:

I just ran into the same issue and the resolution was to put the savefig command before the plt.show() statement, but specify the filetype explicitly. Here is my code:

plt.suptitle("~~~~")
plt.title("~~~~")
ax = sns.boxplot(x=scores_df.score, y=scores_df.response)
plt.savefig("test.png", format="png") # specify filetype explicitly
plt.show()

plt.close()

Solution 3:

Your plot cannot be generated because you defined the list axis_x having only the length 9, while grd and grd2 have the length equal to 10. Just replace the definition of axis_x with:

axis_x=range(1,11) and your plot will show up and it will be saved OK.