2

I currently have a main script, calling a function. Part of that functions functionality is plotting two graphs. The script works if I include show() at the end, but it is a bit annoying that either the script pauses until I close the graph or I have to wait to look at the graphs until the program is finished. Hence I feel like I need to use ion()/ioff(). The code snippet below works if I call the function from the shell, but not if I call it from the script.

#Plot the graphs.
ion()
firstplot = plot(GridAround[Mode], LogTheory[Mode], '.')
secondplot = plot(GridAround[Mode], NormalApprox[Mode])
draw()
ioff()

My question is simply: How do I plot from within a function, without using show() (which will pause the script or only show the graphs at the end)?

I apologize in advance, this question surely must have an answer somewhere on the web, but after a couple of hours of searching, I have not been able to find it.

1
  • 1
    As it turns out, a solution that makes it work for me is: fig = figure() plot(blah) fig.show() This does not halt the execution of the code, and allows the figure to be shown. However, the documentation on figure.show() is as far as I can tell virtually non-existent. Commented May 17, 2011 at 12:06

1 Answer 1

1

You can use a different rendering backend, however, you will need to save the plot as a file with savefig instead of using show

import matplotlib
matplotlib.use('Agg')
Sign up to request clarification or add additional context in comments.

2 Comments

Saving the images is a solution, but not a very good one for my purposes. However, figure.show() seems to be doing what I want.
@Har: I'm glad you figured it out, I guess I misinterpreted what you were asking about.

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.