show() at the end of each function of an ensemble of scripts

Hello,

I’m currently writing a specialized image processing package using Matplotlib. The goal would be to let users use it interactively from an ipython console.

So I have some functions for selecting points on plots (via “button_press_event”), and others for data plotting (and also for data processing, of course). When the user calls a plotting or a point-selecting function, I have to call plt.show() at the end of it… but then this seems to do something irreversible which cannot be cancelled e.g. by plt.ioff(). But at the same time I can’t stay in show() mode forever, because if I did so, the program would fail when the user calls another point-selecting function (as the call to the point-selecting function becomes non-blocking, Python raises an error when the yet undefined coordinates are read in a following part of the enclosing function). (For the same reason, trying to use ipython -pylab leads to failure starting from the first call to a point-selecting function (instead of the second when using ipython).)

(And I can’t use plt.ginput as I sometimes want to update the plot using some home-made functions while the user selects data on it).

So I have to find a way of showing the plot(s) to the user, and still come back to pre- plt.show() mode after (of course, if there was a way to show the plots without calling plt.show(), that would work too)… I believe this is a “classic” question, but I haven’t found an answer to it. So does anyone have an idea about it?

Thanks in advance,

Antony

What you really need is to have ipython integrated into your GUI's
event loop (which is started with show). You might want to look at
Google Code Archive - Long-term storage for Google Code Project Hosting. or Google around for some other
packages that integrate IPython into a GUI.

Ryan

···

On Tue, Apr 20, 2010 at 11:38 AM, Antony Lee <antony.lee@...1839...> wrote:

Hello,

I'm currently writing a specialized image processing package using
Matplotlib. The goal would be to let users use it interactively from an
ipython console.
So I have some functions for selecting points on plots (via
"button_press_event"), and others for data plotting (and also for data
processing, of course). When the user calls a plotting or a
point-selecting function, I have to call plt.show() at the end of it... but
then this seems to do something irreversible which cannot be cancelled
e.g. by plt.ioff(). But at the same time I can't stay in show() mode
forever, because if I did so, the program would fail when the user calls
another point-selecting function (as the call to the point-selecting
function becomes non-blocking, Python raises an error when the yet undefined
coordinates are read in a following part of the enclosing function). (For
the same reason, trying to use ipython -pylab leads to failure starting
from the *first* call to a point-selecting function (instead of the second
when using ipython).)
(And I can't use plt.ginput as I sometimes want to update the plot using
some home-made functions while the user selects data on it).
So I have to find a way of showing the plot(s) to the user, and still come
back to pre- plt.show() mode after (of course, if there was a way to show
the plots without calling plt.show(), that would work too)... I believe this
is a "classic" question, but I haven't found an answer to it. So does anyone
have an idea about it?

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

That would be a solution, indeed. However, is there really no way of coming back to a pre-plt.show() state once all windows are closed? What kind of irreversible things does plt.show() do?

Thanks,

Antony

2010/4/20 Ryan May <rmay31@…287…>

···

On Tue, Apr 20, 2010 at 11:38 AM, Antony Lee <antony.lee@…1839…> wrote:

Hello,

I’m currently writing a specialized image processing package using

Matplotlib. The goal would be to let users use it interactively from an

ipython console.

So I have some functions for selecting points on plots (via

“button_press_event”), and others for data plotting (and also for data

processing, of course). When the user calls a plotting or a

point-selecting function, I have to call plt.show() at the end of it… but

then this seems to do something irreversible which cannot be cancelled

e.g. by plt.ioff(). But at the same time I can’t stay in show() mode

forever, because if I did so, the program would fail when the user calls

another point-selecting function (as the call to the point-selecting

function becomes non-blocking, Python raises an error when the yet undefined

coordinates are read in a following part of the enclosing function). (For

the same reason, trying to use ipython -pylab leads to failure starting

from the first call to a point-selecting function (instead of the second

when using ipython).)

(And I can’t use plt.ginput as I sometimes want to update the plot using

some home-made functions while the user selects data on it).

So I have to find a way of showing the plot(s) to the user, and still come

back to pre- plt.show() mode after (of course, if there was a way to show

the plots without calling plt.show(), that would work too)… I believe this

is a “classic” question, but I haven’t found an answer to it. So does anyone

have an idea about it?

What you really need is to have ipython integrated into your GUI’s

event loop (which is started with show). You might want to look at

http://code.google.com/p/spyderlib/ or Google around for some other

packages that integrate IPython into a GUI.

Ryan

Ryan May

Graduate Research Assistant

School of Meteorology

University of Oklahoma


Download Intel® Parallel Studio Eval

Try the new software tools for yourself. Speed compiling, find bugs

proactively, and fine-tune applications for parallel performance.

See why Intel Parallel Studio got high marks during beta.

http://p.sf.net/sfu/intel-sw-dev


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

It starts the GUI toolkit event loop, which starts to make things
messy if you try to call show() again. It often works, but calling
show() more than once is most-definitely not supported.

Now, depending on what exactly you're trying to do, you can set
everything up to work off of events from the GUI so that once you call
show(), the user can click on
various things and trigger actions. Have you looked at the examples
in: examples/event_handling?

Ryan

···

On Tue, Apr 20, 2010 at 4:44 PM, Antony Lee <antony.lee@...1839...> wrote:

That would be a solution, indeed. However, is there really no way of coming
back to a pre-plt.show() state once all windows are closed? What kind of
irreversible things does plt.show() do?

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

2010/4/20 Ryan May <rmay31@…287…>

That would be a solution, indeed. However, is there really no way of coming

back to a pre-plt.show() state once all windows are closed? What kind of

irreversible things does plt.show() do?

It starts the GUI toolkit event loop, which starts to make things

messy if you try to call show() again. It often works, but calling

show() more than once is most-definitely not supported.
OK, I can understand this…

Now, depending on what exactly you’re trying to do, you can set

everything up to work off of events from the GUI so that once you call

show(), the user can click on

various things and trigger actions. Have you looked at the examples

in: examples/event_handling?
Well, the problem isn’t there (I believe). The workflow I’d like to implement is that, for example the user does some data processing (in ipython), plots some data (I need a show() here), closes the plot window, does some other data processing (in ipython), plots other data (no show() needed here, as we’re still in show() mode) and selects some data by clicking on the plot (I use fig.canvas.mpl_connect, as in the examples/event_handling). The last part works if it’s the first time I’m show()ing a plot, but not the second time, and, looking at the tracebacks, it seems that this is because the first time, the program waits for the window to be closed to continue (so it can access the data it retrieves from the button_press_events), but the second time, it doesn’t – so of course it tries to access undefined variables.

So basically, what I want (if I am not mistaken about the origin of the problem) is to have blocking calls again for my second plot. Buf ioff() isn’t sufficient for this, either (which is not a surprise as show() does more than ion()).

Probably at some point I’ll have to rewrite the whole lot for a specific backend, but I’d like to stick to a pure matplotlib solution as for now.

Thanks in advance,

Antony

···

On Tue, Apr 20, 2010 at 4:44 PM, Antony Lee <antony.lee@…1839…> wrote:

Ryan

Ryan May

Graduate Research Assistant

School of Meteorology

University of Oklahoma

Antony Lee wrote:

Well, the problem isn't there (I believe). The workflow I'd like to implement is that, for example the user does some data processing (in ipython), plots some data (I need a show() here), closes the plot window, does some other data processing (in ipython),

I'm bit confused -- does ipython pylab mode not work for this? That's what it's for.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

But what exactly does show() do that prevents it from being called again? At least for the Mac OS X and the gtkcairo backends, calling show() multiple times doesn't seem to cause any problems. Can you give an example where calling show() multiple times breaks things? If there is such a case, it may reveal a lurking bug in show() itself.

--Michiel.

···

--- On Tue, 4/20/10, Ryan May <rmay31@...287...> wrote:

Antony Lee <antony.lee@...1839...> wrote:
> That would be a solution, indeed. However, is there
> really no way of coming back to a pre-plt.show() state
> once all windows are closed? What kind of
> irreversible things does plt.show() do?

It starts the GUI toolkit event loop, which starts to make
things messy if you try to call show() again. It often works,
but calling show() more than once is most-definitely not
supported.

http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show

hth,
Alan Isaac

Well, the example with the comment "WARNING : illustrating how NOT to use show":

for i in range(10):
    # make figure i
    show()

works perfectly fine with the Mac OS X backend, and I doubt that there is some fundamental reason why this can work with the Mac OS X backend but not with other backends.

--Michiel

···

--- On Tue, 4/20/10, Alan G Isaac <alan.isaac@...287...> wrote:

From: Alan G Isaac <alan.isaac@...287...>
Subject: Re: [Matplotlib-users] show() at the end of each function of an ensemble of scripts
To: matplotlib-users@lists.sourceforge.net
Date: Tuesday, April 20, 2010, 9:51 PM
http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show

hth,
Alan Isaac

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Actually which backend are you using? I’d like to try this to see what happens if show() is called more than once.
–Michiel.

···

— On Tue, 4/20/10, Antony Lee <antony.lee@…878…1839…> wrote:

That would be a solution, indeed. However, is there really no way of coming back to a pre-plt.show() state once all windows are closed? What kind of irreversible things does plt.show() do?

I’m using wxagg, but actually it’s working now… I put show()s a bit everywhere in my code so I must confess I don’t really know how it’s working, though I’ll probably have to go back and clean the mess at some point.

Antony

2010/4/22 Michiel de Hoon <mjldehoon@…9…>

···

Actually which backend are you using? I’d like to try this to see what happens if show() is called more than once.

–Michiel.

— On Tue, 4/20/10, Antony Lee <antony.lee@…1839…> wrote:

That would be a solution, indeed. However, is there really no way of coming back to a pre-plt.show() state once all windows are closed? What kind of irreversible things does plt.show() do?