Is it possible to have multiple PyPlot windows? Or am I limited to subplots?
I'm not sure how to word my question more clearly. Basically, is PyPlot limited to one instance/window? Any hack or workaround I try either causes my program to freeze or for the second pyplot window to be queued until the first one is closed.
Solution 1:
Sure, just open a new figure:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.figure()
plt.plot(range(10), 'ro-')
plt.figure(), plt.plot(...)
plt.show() # only do this once, at the end
If you're running this in the default python interpreter, this won't work, as each figure needs to enter the gui's mainloop. If you want to run things in an interactive shell, look into IPython. If you just run this normally (i.e. put it into a file and call python filename.py
) it will work fine, though.
Solution 2:
Use plt.figure()
and use a certain number so that the window is fixed:
plt.figure(200)
plt.plot(x)
plt.show()
and for another plot, use a different number:
plt.figure(300)
plt.plot(y)
plt.show()