On 8/22/07, Angus McMorland <amcmorl@...> wrote:
> > I would like to use mpl_connect and disconnect to examine a series of 2d
> > arrays in turn (with a "for" loop), one after the other:
> >
> > ==> at each iteration I'd like to be able to use the left mouse button
> > to evaluate the sum of all x,y coordinates I select by (right) clicking
> > somewhere in the present array, and then switch to the next 2d data
> > array after I hit the right mouse button (button==3). I have no clue how
> > to do this and the program I wrote so far is just hanging there and does
> > nothing. Didn't see anything like this in the archive.
> >
> > Any way to get out of this? Thanks for your help.
>
> As a general rule of thumb, if you're using a loop like while
> newoffset.stay: pass, then you're doing something wrong.
Angus is right w/ resepct to mpl -- we don't have any support for
blocking calls. This is a very frequent request and you are certainly
right Eric to *expect* something like this to work, but in the context
of multiple GUIs w/ threads it is not too easy. One could probably
make tkagg work with only minor modifications to mpl, but the other
GUIs would be harder becasue they are threaded. So using event
handling and callbacks are the way to solve this problem, as Angus
suggests in his solution, but they are harder for people to get their
head around than blocking calls, so hopefully we will get support for
this idiom before the end of time.
JDH

Hi Eric,
On 23/08/07, Eric Emsellem <emsellem@...> wrote:
> Hi
>
> sorry to post this again but all my attempts to solve the matplotlib
> problem below failed and I desperately need this to progress.
>
> I would like to use mpl_connect and disconnect to examine a series of 2d
> arrays in turn (with a "for" loop), one after the other:
>
> ==> at each iteration I'd like to be able to use the left mouse button
> to evaluate the sum of all x,y coordinates I select by (right) clicking
> somewhere in the present array, and then switch to the next 2d data
> array after I hit the right mouse button (button==3). I have no clue how
> to do this and the program I wrote so far is just hanging there and does
> nothing. Didn't see anything like this in the archive.
>
> Any way to get out of this? Thanks for your help.
As a general rule of thumb, if you're using a loop like while
newoffset.stay: pass, then you're doing something wrong. This will
take control of all execution and let nothing else happen. You have to
do the control by switching between functions. Here's a modification
to your code that I think does what you want:
import numpy as n
import pylab as p
class offset:
def __init__(self, parent) :
self.parent = parent
self.xc = 0.
self.yc = 0.
self.stay = 1
def on_click(self, event) :
if event.button == 1:
if event.inaxes is not None:
print "Adding point %d, %d" % (event.xdata, event.ydata)
self.xc += event.xdata
self.yc += event.ydata
elif event.button == 3:
print "Switching data"
self.parent.show_next()
class displayer:
def __init__(self):
self.i = 0
self.alldata = [n.random.rand(10,10) for x in xrange(3)]
self.newoffset = offset(self)
self.binding = p.connect('button_press_event', self.newoffset.on_click)
self.show_next()
def show_next(self):
if self.i < len(self.alldata):
p.imshow(self.alldata[self.i])
self.i += 1
else:
p.disconnect(self.binding)
print self.newoffset.xc, self.newoffset.yc
I hope that helps you see the concept.
Angus.
--
AJC McMorland, PhD Student
Physiology, University of Auckland

Hi Chris,
Sorry to bring it up. I know you didn't make the decision so I'll shut up
about it right after I say the following:
"That was a really dumb/weak reason for breaking the standard 'discussion
list' format"
What a pain.
Greg
On 8/22/07, Christopher Barker <Chris.Barker@...> wrote:
>
> Greg Willden wrote:
> > It seems that the list configuration is somewhat broken.
> > The reply-to header is not set in some emails sent to the list.
> > This means that replies go directly to the requestors but not to the
> > list as a whole.
> >
> > That seems pretty broken to me.
>
> me too, but there are folks that are convinced that this is the way to
> have things set up. There was a pretty extensive discussion about it on
> this list a year or so ago (but it may have been another list I'm on).
> The discussion included a link to someones very well written BLOG entry
> on why mailing lists should be set up without the reply-to header sent.
> It was very well written and argued, but frankly, I think, based on
> false assumptions.
>
> It comes down to this:
>
> Which is worse (pro-rated by how likely it is)?
>
> Accidentally sending what was intended as a private note to the list.
>
> or
>
> Accidentally sending what was meant as a list note to only the OP and
> often ending up with many copies of the same message, as reply-to all
> keeps adding each contributor to the thread.
>
> Note that with the current system, you have to hit "reply-to-all", which
> ends up sending duplicate copies to the OP (and anyone else that has
> added to the thread) unless you make a point of deleting the extra
> receiver. I try to do that, but it is a pain.
>
> However, this has been argued out, and a decision made, so I probably
> shouldn't have written this. Sorry.
>
> -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@...
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Linux. Because rebooting is for adding hardware.

Greg Willden wrote:
> It seems that the list configuration is somewhat broken.
> The reply-to header is not set in some emails sent to the list.
> This means that replies go directly to the requestors but not to the
> list as a whole.
>
> That seems pretty broken to me.
me too, but there are folks that are convinced that this is the way to
have things set up. There was a pretty extensive discussion about it on
this list a year or so ago (but it may have been another list I'm on).
The discussion included a link to someones very well written BLOG entry
on why mailing lists should be set up without the reply-to header sent.
It was very well written and argued, but frankly, I think, based on
false assumptions.
It comes down to this:
Which is worse (pro-rated by how likely it is)?
Accidentally sending what was intended as a private note to the list.
or
Accidentally sending what was meant as a list note to only the OP and
often ending up with many copies of the same message, as reply-to all
keeps adding each contributor to the thread.
Note that with the current system, you have to hit "reply-to-all", which
ends up sending duplicate copies to the OP (and anyone else that has
added to the thread) unless you make a point of deleting the extra
receiver. I try to do that, but it is a pain.
However, this has been argued out, and a decision made, so I probably
shouldn't have written this. Sorry.
-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@...

Sebastian Krieger wrote:
> Hi,
>
> Does anyone eventually have a sample on how to make Hovmoller plots
> using matplotlib? Specially with good looking time axis like Ferret does?
>
> Thanks
> Sebastian
>
>
>
Sebastian: Don't have a hovmoller example handy, but you can see how to
make a nice time axis by looking at date_demo.py at
http://matplotlib.sourceforge.net/screenshots.html. Just replace the
line plot with a contour plot, and there you go.
-Jeff
--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

It seems that the list configuration is somewhat broken.
The reply-to header is not set in some emails sent to the list.
This means that replies go directly to the requestors but not to the list as
a whole.
That seems pretty broken to me.
Any list admin out there want to comment.
(by replying to matplotlib-users@... of course)
Greg
--
"Java: The COBOL of the 90's" -Paul Rubin on comp.lang.python

Hi
sorry to post this again but all my attempts to solve the matplotlib
problem below failed and I desperately need this to progress.
I would like to use mpl_connect and disconnect to examine a series of 2d
arrays in turn (with a "for" loop), one after the other:
==> at each iteration I'd like to be able to use the left mouse button
to evaluate the sum of all x,y coordinates I select by (right) clicking
somewhere in the present array, and then switch to the next 2d data
array after I hit the right mouse button (button==3). I have no clue how
to do this and the program I wrote so far is just hanging there and does
nothing. Didn't see anything like this in the archive.
Any way to get out of this? Thanks for your help.
Eric
#=================
# stupid simple code just to illustrate the kind of things I would like to achieve
# This does not work and just hang there...
#=================
import numpy as num
class offset:
def __init__(self) :
self.xc = 0.
self.yc = 0.
self.stay = 1
def on_click(self, event) :
if event.button == 1:
if event.inaxes is not None:
self.xc += event.xdata
self.yc += event.ydata
elif event.button == 3:
self.stay = 0
data1 = num.random.rand(10,10)
data2 = num.random.rand(10,10)
data3 = num.random.rand(10,10)
alldata = [data1, data2, data3]
for i in range(len(alldata)) :
imshow(alldata[i])
newoffset = offset()
binding = connect('button_press_event', newoffset.on_click)
while newoffset.stay :
pass
disconnect(binding)
print newoffset.xc, newoffset.yc

I am sorry, here the better explanation:
I have a scirpt to reduce data. from time to time it should bring up an
interactive matplotlib figure and then when I close the window it should
continue.it is important for me that the script actually stops when
opening the window.
The problem is (which I found out just now) I am running this in ipython
and if I close the window the gtk.mainloop() stays active and doesnt let
me continue my script. So i'm looking for a fucntion I can call to stop
the backend thread. I know there is a thread called gtk.gdk.thread_leave
but I need the appropriate TK object which is the window(or
matplotlib_object or whatever) to call this function. I am happy to use
another backend but I am fairly new to tk and gtk in python so I didnt
see anything else.
thanks in advance
Wolfgang
John Hunter wrote:
> On 8/22/07, Wolfgang Kerzendorf <wkerzendorf@...> wrote:
>
>> Is there any way I can stop the mainloop of the gtkagg backend. i know
>> there is a threads_leave thing but I neec the Tk object from matplotlib.
>> The problem is that my script doesnt continue after the window has been
>> closed
>>
>
> I am not exactly sure what you are after ... Do you need to use
> GTKAgg at all, or can you simply set your backend to TkAgg in your
> matplotlibrc and leave it at that. If for some reason you need
> GTKAgg, and then need to switch to TkAgg, it may be possible to do
> this with the "switch_backend" function in pylab. I have done this on
> occasion with success, but it is mostly experimental. Perhaps if you
> explain your use case a little better we can advise more.
>
>

On 8/22/07, Wolfgang Kerzendorf <wkerzendorf@...> wrote:
> Is there any way I can stop the mainloop of the gtkagg backend. i know
> there is a threads_leave thing but I neec the Tk object from matplotlib.
> The problem is that my script doesnt continue after the window has been
> closed
I am not exactly sure what you are after ... Do you need to use
GTKAgg at all, or can you simply set your backend to TkAgg in your
matplotlibrc and leave it at that. If for some reason you need
GTKAgg, and then need to switch to TkAgg, it may be possible to do
this with the "switch_backend" function in pylab. I have done this on
occasion with success, but it is mostly experimental. Perhaps if you
explain your use case a little better we can advise more.

Is there any way I can stop the mainloop of the gtkagg backend. i know
there is a threads_leave thing but I neec the Tk object from matplotlib.
The problem is that my script doesnt continue after the window has been
closed
thanks in advance
Wolfgang

Andrew Jaffe <a.h.jaffe@...> writes:
> I admit I don't understand the problems or the speccific code involved,
> but I *think* it may be that the OSX-specific code isn't restricted to
> afm files. Hence I wonder if the following is a fix:
> - for f in OSXInstalledFonts():
> + for f in OSXInstalledFonts(fontext=fontext):
It helps in this particular case, but I think the intention behind this
code is to allow loading non-TrueType fonts even when fontext='ttf'. On
OS X there are various non-TrueType font formats (dfont, otf,
resource-fork fonts), at least some of which are supported by freetype,
so if you always pass fontext to OSXInstalledFonts, you unnecessarily
limit the fonts found to those whose filename indicates ttf format.
(Macs also don't care as much about filename extensions as the rest of
the world.)
But I'm just guessing here as to the reasoning behind the code. Somebody
else might know better?
--
Jouni K. Seppänen
http://www.iki.fi/jks

The script I am writing gets sometimes stuck after show(). Of course
show() halts the script but when I close the window I want it to
continue. Is there a sure way to kill off the pylab thread and continue
like with a key press event on ESC and then calling a stop routine of
the thread.
Thanks in advance
Wolfgang