In matplotlib, is there a way to pop up a figure asynchronously?

First things first, don't forget a simple alternative is to just make new figure windows with plt. Figure(2) plt. Figure(3) etc.If you really want to update the existing figure window, you had better keep a handle on your lines object with h = ax.

Plot(1,2,3,4,5,6,'ro-') And then later you would be doing something like: h0. Set_data(some_new_results) ax.figure.canvas.draw() As for the real meat of the question, if you're still battling with this read on You need to enable interactive mode if you want plt.show() to be non-blocking.To modify your runnable example so that doing something else now would print immediately, as opposed to waiting for the figure window to be closed, the following would do:! /usr/bin/python import pylab as plb import matplotlib.

Pyplot as plt fig1=plt. Figure(1) ax = fig1. Add_subplot(1,1,1) ax.

Plot(1,2,3,4,5,6,'ro-') #fig1.show() # this does not show a figure if uncommented plt.ion() # turns on interactive mode plt.show() # now this should be non-blocking print "doing something else now" raw_input('Press Enter to continue...') However, this is just scratching the surface of things - there are many complications once you start wanting to do background work while interacting with the plots. This is a natural consequence of painting with what's essentially a state machine, it doesn't rub well with threading and programming in an object-oriented environment Expensive calculations will have to go into worker threads (or alternatively into subprocesses) to avoid freezing the GUI Queue should be used to pass input data and get results out of the worker functions in a thread-safe way In my experience, it is not safe to call draw() in the worker thread so you also need to set up a way to schedule a repaint Different backends may start to do strange things and TkAgg seems to be the only one which works 100% (see here ) The easiest and best solution is not to use the vanilla python interpreter, but to use ipython -pylab (as ianalis has rightly suggested), because they have already figured out most of the tricks needed to get interactive stuff working smoothly. It can be done without ipython pylab but it's a significant amount of extra work Note: I still often like to farm off worker threads whilst using ipython and pyplot GUI windows, and to get threading working smoothly I also need to use another commandline argument ipython -pylab -wthread I'm on python 2.7.1 with matplotlib v1.1.0 your mileage may vary.

Hope this helps! Note for Ubuntu users : The repositories are still back on v0.99 for quite some time now, it is worth upgrading your matplotlib because there were many improvements coming up to the v1.0 release including a Bugfix marathon and major changes to the behaviour of show().

First things first, don't forget a simple alternative is to just make new figure windows with plt. Figure(2), plt. Figure(3) etc.If you really want to update the existing figure window, you had better keep a handle on your lines object with h = ax.

Plot(1,2,3,4,5,6,'ro-') And then later you would be doing something like: h0. Set_data(some_new_results) ax.figure.canvas.draw() As for the real meat of the question, if you're still battling with this read on.. You need to enable interactive mode if you want plt.show() to be non-blocking.To modify your runnable example so that "doing something else now" would print immediately, as opposed to waiting for the figure window to be closed, the following would do: #! /usr/bin/python import pylab as plb import matplotlib.

Pyplot as plt fig1=plt. Figure(1) ax = fig1. Add_subplot(1,1,1) ax.

Plot(1,2,3,4,5,6,'ro-') #fig1.show() # this does not show a figure if uncommented plt.ion() # turns on interactive mode plt.show() # now this should be non-blocking print "doing something else now" raw_input('Press Enter to continue...') However, this is just scratching the surface of things - there are many complications once you start wanting to do background work while interacting with the plots. This is a natural consequence of painting with what's essentially a state machine, it doesn't rub well with threading and programming in an object-oriented environment. Expensive calculations will have to go into worker threads (or alternatively into subprocesses) to avoid freezing the GUI.

Queue should be used to pass input data and get results out of the worker functions in a thread-safe way.In my experience, it is not safe to call draw() in the worker thread so you also need to set up a way to schedule a repaint. Different backends may start to do strange things and TkAgg seems to be the only one which works 100% (see here). The easiest and best solution is not to use the vanilla python interpreter, but to use ipython -pylab (as ianalis has rightly suggested), because they have already figured out most of the tricks needed to get interactive stuff working smoothly.It can be done without ipython/pylab but it's a significant amount of extra work.

Note: I still often like to farm off worker threads whilst using ipython and pyplot GUI windows, and to get threading working smoothly I also need to use another commandline argument ipython -pylab -wthread. I'm on python 2.7.1+ with matplotlib v1.1.0, your mileage may vary. Hope this helps!

Note for Ubuntu users: The repositories are still back on v0.99 for quite some time now, it is worth upgrading your matplotlib because there were many improvements coming up to the v1.0 release including a Bugfix marathon, and major changes to the behaviour of show().

Tried your example with plt.ion(). Doesn't work for me, plt.show() is still blocking it. I'm on Ubuntu 10.04, python 2.6.5, matplotlib 0.99.Is that just way too old?

– Zhenya Sep 12 at 17:02 Perhaps it is way too old: they have changed the implementation of show() quite significantly back for v1.0 ( see here matplotlib.sourceforge. Net/users/… ). What do you get if you move the plt.ion() line up to the top of the script, i.e.

After the import matplotlib. Pyplot as plt? And what is the result of calling function matplotlib.

Get_backend()? – wim Sep 12 at 23:55 get_backend() returns TkAgg, and there's no change if the the plt.ion() is the first line of the script. – Zhenya Sep 13 at 12:29.

Probably the easiest solution is to use IPython as your python shell. Run it with the -pylab option. Ipython -pylab.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions