Possible Duplicate:
How to make the plot not disappear?
I am writing a command line interface python program for analysing some data. It asks the user a bunch of questions and at a few points in the script a matplotlib pyplot plot neds to be shown, but I want to show it and continue with the script something like below:
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
plt.plot(np.arange(10),np.arange(10)**2)
plt.show()
print 'continuing the program'
I have tried using plt.draw() along with subplots but it doesn’t seem to work inside a script.
edit:
I have used plt.ion() which kind of works except the plot windows are unresponsive, and the zoom in tool etc buttons aren’t shown
plt.show()will not return until the user closes the widget/window. I many cases this behavior is fine. Why should the script proceed while the user spends time looking at a wonderful graph anyway? 🙂 If you, however, require your program to proceed, make use of thethreadingmodule. Invokeplt.show()in a new thread andjoin()this thread before letting your main thread terminate.Edit:
It looks like things are not that simple. I created the following
test.py:Testing it results in this error:
I infer from this that
p.show()is required to be called from the main thread. Maybe you have to do it the other way round: get your user input in another thread.