1

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

1 Answer 1

1

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.

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

1 Comment

Ahh that explains it... I suspected it was plot.show() so I commented that line out and it did successfully save everything and do what I wanted.Thanks for your explanation though, I just did trial and error and it worked but wasn't too sure why

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.