1

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 :)

5
  • Turn on interactive mode. import matplotlib.pyplot as plt; plt.ion() Commented Apr 21, 2017 at 8:54
  • Thanks, that helps, but now the new plot is in the same window, so i still can't Keep the old one. Commented Apr 21, 2017 at 8: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). Commented Apr 21, 2017 at 9:03
  • Thank you :) and which ordering is correct? because now I get Windows which don't have any Content as well... Commented Apr 21, 2017 at 9:21
  • I am no psychic. Without seeing your code it's impossible to tell. Presumably, you are initialising too many new figures now. Commented Apr 21, 2017 at 9:23

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

This is better answer than the one accepted.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.