Suppose you need to store the figure
and subplot
in variables (to later modify attributes). How can you make the whole figure to stay and not quickly disappear after some millisecs?
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(2,2,1)
ax.plot(1)
fig.show()
We can simply save plots generated from Matplotlib using savefig() and imsave() methods. If we are in interactive mode, the plot might get displayed. To avoid the display of plot we use close() and ioff() methods.
You can either (a) allow blocking on your last plot, or (b) don't exit the script (perhaps ask for input: "press <Enter> to exit plot" or something like that).
Change fig
to plt
:
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With