Matplotlib (pyplot) savefig outputs blank image Matplotlib (pyplot) savefig outputs blank image python python

Matplotlib (pyplot) savefig outputs blank image

First, what happens when T0 is not None? I would test that, then I would adjust the values I pass to plt.subplot(); maybe try values 131, 132, and 133, or values that depend whether or not T0 exists.

Second, after is called, a new figure is created. To deal with this, you can

  1. Call plt.savefig('tessstttyyy.png', dpi=100) before you call

  2. Save the figure before you show() by calling plt.gcf() for "get current figure", then you can call savefig() on this Figure object at any time.

For example:

fig1 = plt.gcf()'tessstttyyy.png', dpi=100)

In your code, 'tesssttyyy.png' is blank because it is saving the new figure, to which nothing has been plotted. should come after plt.savefig()

Explanation: clears the whole thing, so anything afterwards will happen on a new empty figure

change the order of the functions fixed the problem for me:

  • first Save the plot
  • then Show the plot

as following: