I have a Python Script which is producing a plot, everything works fine. But I would like to keep this plot open (to compare it with others), this doesn't work, the script doesn't continue to run until I have closed the plot window. Any suggestions what I can do? Thanks :)
Asked
Active
Viewed 2,934 times
1
-
Turn on interactive mode. `import matplotlib.pyplot as plt; plt.ion()` – Paul Brodersen Apr 21 '17 at 08:54
-
Thanks, that helps, but now the new plot is in the same window, so i still can't Keep the old one. – Judith Apr 21 '17 at 08:57
-
Initialise a new figure before each plot. `plt.figure()`. Alternatively, be more explicit on which axis you are plotting stuff: `fig, (ax1, ax2) = plt.subplots(1,2); ax1.plot(x1, y1); ax2.plot(x2, y2)`. – Paul Brodersen Apr 21 '17 at 09:03
-
Thank you :) and which ordering is correct? because now I get Windows which don't have any Content as well... – Judith Apr 21 '17 at 09:21
-
I am no psychic. Without seeing your code it's impossible to tell. Presumably, you are initialising too many new figures now. – Paul Brodersen Apr 21 '17 at 09:23
2 Answers
1
If you use plt.ion()
instead of plt.show()
the script will continue to run without you needing to close the window and the plot will update in the open window.
Alternatively, you can use plt.show(block=False)

patapouf_ai
- 17,605
- 13
- 92
- 132
0
When calling plt.show()
the event loop is transfered to the window shown. The rest of the program will only continue once that window is closed.
The suggestion would be to simply call plt.show()
at the end of the script, when all figures are ready to be shown at once.

ImportanceOfBeingErnest
- 321,279
- 53
- 665
- 712