Reputation: 119
I have several files that I am currently turning into functions. Each function makes a plot from a csv file and works successfully on its own. I am now trying to combine them all into the one code that will call each function and create the plots all at once. The issue that I'm having is that I am calling the functions correctly except only one plot will open. The second (and subsequent) don't open until the previous one is closed. My code is:
#!usr/bin/python
import os.path
from Ux import Ux_plotting
from prgh import prgh_plotting
print "Creating post-processing plots..."
if os.path.exists("Ux.py") and os.path.exists("Uz.py") and os.path.exists("prgh.py") and os.path.exists("forces.py") and os.path.exists("magvorticity.py"):
print "All good. Next step..."
else:
print "Uh oh. Better make sure you have all of your files."
Ux_plotting()
prgh_plotting()
Anybody have some advice on this?
I'm trying to write my first python codes so please be patient :-)
Upvotes: 1
Views: 258
Reputation: 69126
I assume you have plt.show()
at the end of your Ux_plotting
and prgh_plotting
functions. plt.show()
is a blocking function: i.e. it will show any figures, and stop anything else happening until the figure window is closed.
I think you have (at least) two options;
1) move the plt.show()
into your main script, after your two plotting calls, since (from the docs), show()
will show all figures created:
matplotlib.pyplot.show(*args, **kw)
Display a figure.
In non-interactive mode, display all figures and block until the figures have been closed
2) Alternatively, you could try setting block=False
in the first plotting function's show
: plt.show(block=False)
, which should allow the code to continue until the next plt.show()
in the second plotting function.
Upvotes: 1