The docs matplotlib.pyplot.show — Matplotlib 3.9.2 documentation mention:
At the end of (a blocking)
show()the figure is closed and thus unregistered from pyplot.
I am wondering if it would be possible to add an optional keyword argument to plt.show called clear_figures or similar, to make it possible to avoid clearing figures.
Reasoning: Sometimes I want to view somewhat interactively how a sequence of multiple plots develops. However, interactive mode plt.ion() doesn’t seem suitable. Also, it’s cumbersome to repeat previous plots, because they have been cleared by plt.show(). Thus, it would be wonderful, if I could avoid figures being cleared by showing them.
Here is an example of what I mean:
plt.plot(...) # first plot
plt.show() # unfortunately clears the plot after closing the window
plt.plot(...) # second plot
plt.show() # unfortunately only shows the second plot
So what I currently have to do is:
plt.plot(...) # first plot
plt.show()
plt.plot(...) # repeat first plot
plt.plot(...) # second plot
plt.show()
Which gets infinitely worse the more plots I want to add.
I was thinking it might be possible to do:
plt.plot(...) # first plot
plt.show(clear_figures=False)
plt.plot(...) # second plot
plt.show()
See also my previous related discussion thread Why does plt.show clear all figures? How to avoid that?
Thank you very much for your work on matplotlib and thanks for considering to add this feature. ![]()