I have tried to find solutions to this problem on this site, for example this post, this post, and this one.
I work in engineering, and spend a lot of time plotting data, re-plotting it, adjusting this and that to see how to extract the most information from it in a python shell. However, it's a real pain to each time re-create the plot I want as a new figure. What I want is to be able to re-open a closed figure. Actually, I want to be able to open a figure at all in the pyplot interface.
Typically my workflow might look something like this. I might create a new figure and axes with a call to subplots():
fig, ax = plt.subplots()
Then, I create my plots, perhaps just a simple line plot:
ax.plot(someExistingData)
Now, I will show the plot, using the only way I know how:
plt.show()
Now, after inspecting the plot, I notice that the range is not what I would like, or I want to change the linewidth, or I want to display with circle markers instead of a continuous line, or any of a million things. What I would like to do at this point, after closing the original plot (hitting the red X on the figure that pops up on my computer), is something like:
plt.open(fig)
plt.show()
My understanding is that matplotlib's state interface is only able to find recently-created plots. From the matplotlib documentation about what plt.show()
does:
"Display all open figures."
Great, but how do I open a figure in the first place without creating it from scratch? This seems like a simple task. I have an existing figure -> I want to add it to the list of figures matplotlib thinks is "open", and then I want to show that figure with plt.show()
. However, I can't seem to find a way to "re-open" an existing figure, or even explicitly "open" a figure at all. I know the figure object still exists, and that figure object still contains my old axis that I want to display, I just want to add that figure object to whatever interface matplotlib uses for displaying it.