SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: darkside <in....@gm...> - 2007年06月28日 17:39:27
Hello everyone,
I'm trying to do a program that opens two different plots and select one
point of each one with a mouse event. Here you have my example:
--------------------------
import pylab
def click(event):
 global x # allow to change global variable
 if event.button == 1:
 if event.inaxes:
 x = event.xdata # change global variable
 print " x - intern = ", x
 pylab.disconnect(cid)
 pylab.close()
return x
xlist = [] # list for x values
global x
#for i in xrange(4):
fig = pylab.figure()
ax = fig.add_subplot(111)
pylab.title('primera')
cid = pylab.connect('button_press_event', click)
pylab.show()
print " x - extern = ", x
xlist.append(x)
pylab.close()
fig = pylab.figure()
ax = fig.add_subplot(111)
pylab.title('segunda')
cid = pylab.connect('button_press_event', click)
pylab.show()
print " x - extern = ", x
xlist.append(x)
pylab.close()
--------------------------------------------------
The problem is that the click event only works with the first plot, in the
second one I get the plot, but not the mouse event. So my output is:
 x - intern = 0.696277915633
 x - extern = 0.696277915633
 x - extern = 0.696277915633
As you see, I only get the x-intern once.
Does anybody know what I'm doing wrong?
From: Matthias M. <Mat...@gm...> - 2007年06月28日 18:12:04
Hello darkside,
I tried your example and it works for me (with mpl-svn) using GTKAgg and 
doesn't work (like you reported) using TKAgg (Is this a bug?). 
Maybe you can switch to GTKAgg?
Otherwise you should report the mpl-version you are using.
>-------------------------------------
import matplotlib
#matplotlib.use("TKAgg")
matplotlib.use("GTKAgg")
import pylab
>---------------------------------------
best regards,
Matthias
On Thursday 28 June 2007 19:39, darkside wrote:
> Hello everyone,
> I'm trying to do a program that opens two different plots and select one
> point of each one with a mouse event. Here you have my example:
>
>
> --------------------------
> import pylab
>
> def click(event):
> global x # allow to change global variable
> if event.button == 1:
> if event.inaxes:
> x = event.xdata # change global variable
> print " x - intern = ", x
> pylab.disconnect(cid)
> pylab.close()
> return x
>
> xlist = [] # list for x values
> global x
> #for i in xrange(4):
> fig = pylab.figure()
> ax = fig.add_subplot(111)
> pylab.title('primera')
> cid = pylab.connect('button_press_event', click)
> pylab.show()
> print " x - extern = ", x
> xlist.append(x)
> pylab.close()
>
> fig = pylab.figure()
>
> ax = fig.add_subplot(111)
> pylab.title('segunda')
> cid = pylab.connect('button_press_event', click)
> pylab.show()
> print " x - extern = ", x
> xlist.append(x)
> pylab.close()
> --------------------------------------------------
> The problem is that the click event only works with the first plot, in the
> second one I get the plot, but not the mouse event. So my output is:
> x - intern = 0.696277915633
> x - extern = 0.696277915633
> x - extern = 0.696277915633
> As you see, I only get the x-intern once.
>
> Does anybody know what I'm doing wrong?
From: darkside <in....@gm...> - 2007年06月29日 18:01:04
It's unbeliable. Yes, it works now!!! At least.............. I had spend a
lot of time with these!
So maybe is it a bug? Matplotlib developers: here you have a bug.
Thank you very much for your help, I coud never have thougt that it was the
problem.
2007年6月28日, Matthias Michler <Mat...@gm...>:
>
> Hello darkside,
>
> I tried your example and it works for me (with mpl-svn) using GTKAgg and
> doesn't work (like you reported) using TKAgg (Is this a bug?).
> Maybe you can switch to GTKAgg?
> Otherwise you should report the mpl-version you are using.
> >-------------------------------------
> import matplotlib
> #matplotlib.use("TKAgg")
> matplotlib.use("GTKAgg")
> import pylab
> >---------------------------------------
>
> best regards,
> Matthias
>
> On Thursday 28 June 2007 19:39, darkside wrote:
> > Hello everyone,
> > I'm trying to do a program that opens two different plots and select one
> > point of each one with a mouse event. Here you have my example:
> >
> >
> > --------------------------
> > import pylab
> >
> > def click(event):
> > global x # allow to change global variable
> > if event.button == 1:
> > if event.inaxes:
> > x = event.xdata # change global variable
> > print " x - intern = ", x
> > pylab.disconnect(cid)
> > pylab.close()
> > return x
> >
> > xlist = [] # list for x values
> > global x
> > #for i in xrange(4):
> > fig = pylab.figure()
> > ax = fig.add_subplot(111)
> > pylab.title('primera')
> > cid = pylab.connect('button_press_event', click)
> > pylab.show()
> > print " x - extern = ", x
> > xlist.append(x)
> > pylab.close()
> >
> > fig = pylab.figure()
> >
> > ax = fig.add_subplot(111)
> > pylab.title('segunda')
> > cid = pylab.connect('button_press_event', click)
> > pylab.show()
> > print " x - extern = ", x
> > xlist.append(x)
> > pylab.close()
> > --------------------------------------------------
> > The problem is that the click event only works with the first plot, in
> the
> > second one I get the plot, but not the mouse event. So my output is:
> > x - intern = 0.696277915633
> > x - extern = 0.696277915633
> > x - extern = 0.696277915633
> > As you see, I only get the x-intern once.
> >
> > Does anybody know what I'm doing wrong?
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /