Hi,

I found the problem. It was not a bug of matplotlib (of course should I say). 
It was a bug in my
code (with the click event handling method).

Jonathan

Demaeyer Jonathan a écrit :
> Hi everyone,
> 
> I use matplotlib to render a figure in a tkinter (the Tix library more 
> precisely) canvas.
> It works very well but I can't turn off the autoscale (and I would like to), 
> even by setting
> ax.set_autoscale_on(False). When I test with ax.get_autoscale_on(), the 
> result is False, but the
> axes continues to autoscale.
> 
> I didn't had this problem in the past with ubuntu 8.04. I have it since I 
> made the update to the
> 8.10 distribution so I guess that it's because the version of matplotlib I 
> use have changed also
> (but I don't remember the number of this previous version). Now I use python 
> 2.5.2, Tix 8.4.0, mpl
> 0.98.3, numpy 1.2.1 ppa release, scipy 0.7.0 ppa release.
> 
> Here is the graphic part of my app :
> 
> class GraphFrame(Tix.Frame):
>     def __init__(self,master):
>         Tix.Frame.__init__(self,master,bd=10)
>         self.gen = Tix.Frame(self)
>         self.fps = Figure(figsize=(5,4),dpi=100,facecolor='w')
> 
>         self.tlps = 'Phase Space'
>         self.xlps = {'xlabel' : r'$x$','fontsize' : 16}
>         self.ylps = {'ylabel' : r'$p$','rotation' : 'horizontal','fontsize' : 
> 16}
>         self.aps = self.fps.add_subplot(111)
>         self.aps.set_title(self.tlps)
>         self.aps.set_xlabel(**self.xlps)
>         self.aps.set_ylabel(**self.ylps)
>         self.canvasps = FigureCanvasTkAgg(self.fps,master=self.gen)
>         
> self.canvasps.get_tk_widget().pack(side=Tix.TOP,fill=Tix.BOTH,expand=1)
>         self.toolbar = NavigationToolbar2TkAgg(self.canvasps, self.gen)
>         self.toolbar.update()
>         self.canvasps._tkcanvas.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
>         self.gen.grid(row=0, columnspan=14, sticky='NWSE')
>         self.aps.set_autoscale_on(False) #doesn't work !!!
> #        self.aps.autoscale_view(scalex=False,scaley=False)
>         self.psLin = []
>         self.cl = ('r','g','b','c','y','m','k')
>         self.coch = self.canvasps.mpl_connect('button_press_event', 
> self.onpsclick)
>         self.crh = self.canvasps.mpl_connect('button_release_event', 
> self.onpsrelease)
>         self.cmh = self.canvasps.mpl_connect('motion_notify_event', 
> self.onpsmotion)
>         self.cFrame = None
>         self.press = False
> 
>     def ocps_connect(self):
>         self.coch = self.canvasps.mpl_connect('button_press_event', 
> self.onpsclick)
>         self.crh = self.canvasps.mpl_connect('button_release_event', 
> self.onpsrelease)
>         self.cmh = self.canvasps.mpl_connect('motion_notify_event', 
> self.onpsmotion)
> 
>     def ocps_disconnect(self):
>         self.canvasps.mpl_disconnect(self.coch)
>         self.canvasps.mpl_disconnect(self.crh)
>         self.canvasps.mpl_disconnect(self.cmh)
> 
> #some method I use to update the graph
> 
>     def psaddData_m(self,u,xmin,xmax,pmin,pmax,m=','):
>         line = lines.Line2D(u[:,0],u[:,1],
>                                  linestyle='None',
>                                  marker=m,
>                                  color=self.cl[np.mod(len(self.psLin)-1,6)])
>         self.psLin.append(line)
>         self.psDraw(xmin,xmax,pmin,pmax)
> 
>     def psaddData_l(self,u,xmin,xmax,pmin,pmax,l='-'):
>         line = lines.Line2D(u[:,0],u[:,1],
>                             linestyle=l,
>                             color=self.cl[np.mod(len(self.psLin)-1,6)])
>         self.psLin.append(line)
>         self.psDraw(xmin,xmax,pmin,pmax)
> 
>     def psdelData(self,n):
>         del self.psLin[n]
>         self.aps.clear()
> #        self.aps.cla()
>         for l in self.psLin:
>             self.aps.add_line(l)
>         self.aps.set_title(self.tlps)
>         self.aps.set_xlabel(**self.xlps)
>         self.aps.set_ylabel(**self.ylps)
>         self.aps.redraw_in_frame()
>         self.canvasps.blit()
> 
> 
>     def psDraw(self,xmin,xmax,pmin,pmax):
> #        self.aps.clear()
>         self.aps.cla()
>         self.aps.set_xlim(xmin,xmax)
>         self.aps.set_ylim(pmin,pmax)
>         for l in self.psLin:
>             self.aps.add_line(l)
>         self.aps.set_title(self.tlps)
>         self.aps.set_xlabel(**self.xlps)
>         self.aps.set_ylabel(**self.ylps)
>         self.aps.draw()
>         self.canvasps.blit()
> #        self.aps.set_autoscale_on(False)
> #        self.aps.autoscale_view(scalex=False,scaley=False)
> #        a = self.aps.get_autoscale_on()
> #        print a
> 
>     def psifRedraw(self):
>         self.aps.clear()
> #        self.aps.cla()
>         for l in self.psLin:
>             self.aps.add_line(l)
>         self.aps.set_title(self.tlps)
>         self.aps.set_xlabel(**self.xlps)
>         self.aps.set_ylabel(**self.ylps)
>         self.aps.redraw_in_frame()
>         self.canvasps.blit()
> 
>     def psRedraw(self):
>         self.aps.redraw_in_frame()
>         self.canvasps.blit()
> 
> # click event handling
> 
>     def onpsclick(self,event):
> 
>         Bhv=self.cFrame.stDico['psMode'].get()
> 
>         if event.inaxes!=self.aps: return
>         if Bhv == 'Nothing': return
> 
>         self.press = True
> 
>         if Bhv == 'Traj':
> 
> 
>             niter=int(self.cFrame.stDico['n iter'].get())
>             jb = self.cFrame.TrajJacob.get()
>             if jb:
>                 lj = float(self.cFrame.TJDirlStr.get())
>                 hj = float(self.cFrame.TJDirhderStr.get())
>             jnb = self.cFrame.nTrajJacob.get()
>             if jnb:
>                 ljn = float(self.cFrame.nTJDirlStr.get())
>                 hjn = float(self.cFrame.nTJDirhderStr.get())
> 
>             v = np.array([event.xdata,event.ydata])
>             s = [v]
>             if jb: sj = [Jacob(v,hj,utils.dfridr)]
>             if jnb: sjn = [Jacob(v,hjn,utils.dfridr)]
>             for i in xrange(0,niter):
>                 u = pm.Map(v)
>                 s.append(u)
>                 v = u
>                 if jb: sj.append(Jacob(v,hj,utils.dfridr))
>                 if jnb: sjn.append(np.dot(sjn[-1],Jacob(v,hjn,utils.dfridr)))
>             w = np.vstack(s)
>             line = lines.Line2D(w[:,0],w[:,1],color='b')
>             if jb:
>                 for i in xrange(len(sj)):
>                     J = sj[i]
>                     v = s[i]
>                     (lr,vr) = eig(J,right=True)
>                     if reduce(lambda x,y : (np.abs(x)-1.)*(np.abs(y)-1.),lr) 
> >= 0:
>                         print 'Problem : The point '+str(i+1)+' is not 
> hyperbolic'
>                         print 'J=',J
>                         print 'l=',lr
>                     else:
>                         if abs(lr[0]) < 1.:
>                             u1 = vr[:,0]
>                             u2 = vr[:,1]
>                         else:
>                             u1 = vr[:,1]
>                             u2 = vr[:,0]
>                         ul1 = np.vstack([v-lj*u1,v+lj*u1])
>                         ul2 = np.vstack([v-lj*u2,v+lj*u2])
>                         line1 = lines.Line2D(ul1[:,0],ul1[:,1],color='b')
>                         line2 = lines.Line2D(ul2[:,0],ul2[:,1],color='r')
>                         self.aps.add_line(line1)
>                         self.aps.add_line(line2)
>             if jnb:
>                 for i in xrange(len(sjn)):
>                     J = sjn[i]
>                     v = s[i]
>                     (lr,vr) = eig(J,right=True)
>                     if reduce(lambda x,y : (np.abs(x)-1.)*(np.abs(y)-1.),lr) 
> >= 0:
>                         print 'Problem : The traj '+str(i+1)+' is not 
> hyperbolic'
>                         print 'J=',J
>                         print 'l=',lr
>                     else:
>                         if abs(lr[0]) < 1.:
>                             u1 = vr[:,0]
>                             u2 = vr[:,1]
>                         else:
>                             u1 = vr[:,1]
>                             u2 = vr[:,0]
>                         ul1 = np.vstack([v-ljn*u1,v+ljn*u1])
>                         ul2 = np.vstack([v-ljn*u2,v+ljn*u2])
>                         line1 = lines.Line2D(ul1[:,0],ul1[:,1],color='g')
>                         line2 = lines.Line2D(ul2[:,0],ul2[:,1],color='m')
>                         self.aps.add_line(line1)
>                         self.aps.add_line(line2)
> 
>         elif Bhv == '1it':
>             v = np.array([event.xdata,event.ydata])
>             u = pm.Map(v)
>             w = np.vstack([v,u])
>             line = lines.Line2D(w[:,0],w[:,1],
>                                 linestyle='None',
>                                 marker='+',
>                                 markersize=10.,
>                                 color='k')
>         elif Bhv == 'Preim':
> 
>             xmin=float(self.cFrame.stDico['pixmin'].get())
>             xmax=float(self.cFrame.stDico['pixmax'].get())
>             pmin=float(self.cFrame.stDico['pipmin'].get())
>             pmax=float(self.cFrame.stDico['pipmax'].get())
>             nx=int(self.cFrame.stDico['pinx'].get())
>             ny=int(self.cFrame.stDico['pinp'].get())
>             tol=float(self.cFrame.stDico['pitol'].get())
>             it=int(self.cFrame.stDico['piter'].get())
>             al=float(self.cFrame.stDico['pialpha'].get())
>             npim = self.cFrame.preimmVar.get()
> 
>             v = np.array([event.xdata,event.ydata])
>             u = preMap(npim,v,xmin,xmax,pmin,pmax,nx,ny,tol,it,al)
>             if u != None:
>                 w = np.vstack([v,u])
>             else:
>                 w = v
>                 w.shape = 1,2
>             line = lines.Line2D(w[:,0],w[:,1],
>                                 linestyle='None',
>                                 marker='+',
>                                 markersize=10.,
>                                 color='k')
> 
>         elif Bhv == 'Jacob':
>             l = float(self.cFrame.DirlStr.get())
>             h = float(self.cFrame.DirhderStr.get())
>             v = np.array([event.xdata,event.ydata])
>             J = Jacob(v,h,utils.dfridr)
>             (lr,vr) = eig(J,right=True)
>             if reduce(lambda x,y : (np.abs(x)-1.)*(np.abs(y)-1.),lr) >= 0:
>                 print 'Problem : The point is not hyperbolic'
>                 print 'J=',J
>                 print 'l=',lr
>                 return
>             if abs(lr[0]) < 1.:
>                 u1 = vr[:,0]
>                 u2 = vr[:,1]
>             else:
>                 u1 = vr[:,1]
>                 u2 = vr[:,0]
>             ul1 = np.vstack([v-l*u1,v+l*u1])
>             ul2 = np.vstack([v-l*u2,v+l*u2])
>             line = lines.Line2D(ul1[:,0],ul1[:,1],color='b')
>             line1 = lines.Line2D(ul2[:,0],ul2[:,1],color='r')
>             self.aps.add_line(line1)
> 
>         self.aps.add_line(line)
> #        self.aps.set_title(self.tlps)
> #        self.aps.set_xlabel(**self.xlps)
> #        self.aps.set_ylabel(**self.ylps)
>         self.aps.redraw_in_frame()
>         self.canvasps.blit()
> 
>     def onpsmotion(self,event):
> 
>         Bhv=self.cFrame.stDico['psMode'].get()
> 
>         if event.inaxes!=self.aps: return
>         if self.press == False: return
>         if Bhv == 'Nothing': return
> 
>         self.aps.clear()
> #        self.aps.cla()
>         for l in self.psLin:
>             self.aps.add_line(l)
>         self.aps.set_title(self.tlps)
>         self.aps.set_xlabel(**self.xlps)
>         self.aps.set_ylabel(**self.ylps)
> 
>         if Bhv == 'Traj':
> 
> 
>             niter=int(self.cFrame.stDico['n iter'].get())
>             jb = self.cFrame.TrajJacob.get()
>             if jb:
>                 lj = float(self.cFrame.TJDirlStr.get())
>                 hj = float(self.cFrame.TJDirhderStr.get())
>             jnb = self.cFrame.nTrajJacob.get()
>             if jnb:
>                 ljn = float(self.cFrame.nTJDirlStr.get())
>                 hjn = float(self.cFrame.nTJDirhderStr.get())
> 
>             v = np.array([event.xdata,event.ydata])
>             s = [v]
>             if jb: sj = [Jacob(v,hj,utils.dfridr)]
>             if jnb: sjn = [Jacob(v,hjn,utils.dfridr)]
>             for i in xrange(0,niter):
>                 u = pm.Map(v)
>                 s.append(u)
>                 v = u
>                 if jb: sj.append(Jacob(v,hj,utils.dfridr))
>                 if jnb: sjn.append(np.dot(sjn[-1],Jacob(v,hjn,utils.dfridr)))
>             w = np.vstack(s)
>             line = lines.Line2D(w[:,0],w[:,1],color='b')
>             if jb:
>                 for i in xrange(len(sj)):
>                     J = sj[i]
>                     v = s[i]
>                     (lr,vr) = eig(J,right=True)
>                     if reduce(lambda x,y : (np.abs(x)-1.)*(np.abs(y)-1.),lr) 
> >= 0:
>                         print 'Problem : The point '+str(i+1)+' is not 
> hyperbolic'
>                         print 'J=',J
>                         print 'l=',lr
>                     else:
>                         if abs(lr[0]) < 1.:
>                             u1 = vr[:,0]
>                             u2 = vr[:,1]
>                         else:
>                             u1 = vr[:,1]
>                             u2 = vr[:,0]
>                         ul1 = np.vstack([v-lj*u1,v+lj*u1])
>                         ul2 = np.vstack([v-lj*u2,v+lj*u2])
>                         line1 = lines.Line2D(ul1[:,0],ul1[:,1],color='b')
>                         line2 = lines.Line2D(ul2[:,0],ul2[:,1],color='r')
>                         self.aps.add_line(line1)
>                         self.aps.add_line(line2)
>             if jnb:
>                 for i in xrange(len(sjn)):
>                     J = sjn[i]
>                     v = s[i]
>                     (lr,vr) = eig(J,right=True)
>                     if reduce(lambda x,y : (np.abs(x)-1.)*(np.abs(y)-1.),lr) 
> >= 0:
>                         print 'Problem : The traj '+str(i+1)+' is not 
> hyperbolic'
>                         print 'J=',J
>                         print 'l=',lr
>                     else:
>                         if abs(lr[0]) < 1.:
>                             u1 = vr[:,0]
>                             u2 = vr[:,1]
>                         else:
>                             u1 = vr[:,1]
>                             u2 = vr[:,0]
>                         ul1 = np.vstack([v-ljn*u1,v+ljn*u1])
>                         ul2 = np.vstack([v-ljn*u2,v+ljn*u2])
>                         line1 = lines.Line2D(ul1[:,0],ul1[:,1],color='g')
>                         line2 = lines.Line2D(ul2[:,0],ul2[:,1],color='m')
>                         self.aps.add_line(line1)
>                         self.aps.add_line(line2)
> 
>         elif Bhv == '1it':
>             v = np.array([event.xdata,event.ydata])
>             u = pm.Map(v)
>             w = np.vstack([v,u])
>             line = lines.Line2D(w[:,0],w[:,1],
>                                 linestyle='None',
>                                 marker='+',
>                                 markersize=10.,
>                                 color='k')
>         elif Bhv == 'Preim':
> 
>             xmin=float(self.cFrame.stDico['pixmin'].get())
>             xmax=float(self.cFrame.stDico['pixmax'].get())
>             pmin=float(self.cFrame.stDico['pipmin'].get())
>             pmax=float(self.cFrame.stDico['pipmax'].get())
>             nx=int(self.cFrame.stDico['pinx'].get())
>             ny=int(self.cFrame.stDico['pinp'].get())
>             tol=float(self.cFrame.stDico['pitol'].get())
>             it=int(self.cFrame.stDico['piter'].get())
>             al=float(self.cFrame.stDico['pialpha'].get())
>             npim = self.cFrame.preimmVar.get()
> 
>             v = np.array([event.xdata,event.ydata])
>             u = preMap(npim,v,xmin,xmax,pmin,pmax,nx,ny,tol,it,al)
>             if u != None:
>                 w = np.vstack([v,u])
>             else:
>                 w = v
>                 w.shape = 1,2
>             line = lines.Line2D(w[:,0],w[:,1],
>                                 linestyle='None',
>                                 marker='+',
>                                 markersize=10.,
>                                 color='k')
>         elif Bhv == 'Jacob':
>             l = float(self.cFrame.DirlStr.get())
>             h = float(self.cFrame.DirhderStr.get())
>             v = np.array([event.xdata,event.ydata])
>             J = Jacob(v,h,utils.dfridr)
>             (lr,vr) = eig(J,right=True)
>             if reduce(lambda x,y : (np.abs(x)-1.)*(np.abs(y)-1.),lr) >= 0:
>                 print 'Problem : The point is not hyperbolic'
>                 print 'J=',J
>                 print 'l=',lr
>                 return
>             if abs(lr[0]) < 1.:
>                 u1 = vr[:,0]
>                 u2 = vr[:,1]
>             else:
>                 u1 = vr[:,1]
>                 u2 = vr[:,0]
>             ul1 = np.vstack([v-l*u1,v+l*u1])
>             ul2 = np.vstack([v-l*u2,v+l*u2])
>             line = lines.Line2D(ul1[:,0],ul1[:,1],color='b')
>             line1 = lines.Line2D(ul2[:,0],ul2[:,1],color='r')
>             self.aps.add_line(line1)
> 
> 
>         self.aps.add_line(line)
> #        self.aps.set_title(self.tlps)
> #        self.aps.set_xlabel(**self.xlps)
> #        self.aps.set_ylabel(**self.ylps)
>         self.aps.redraw_in_frame()
>         self.canvasps.blit()
> 
>     def onpsrelease(self,event):
>         self.press = False
>         self.aps.clear()
> #        self.aps.cla()
>         for l in self.psLin:
>             self.aps.add_line(l)
>         self.aps.set_title(self.tlps)
>         self.aps.set_xlabel(**self.xlps)
>         self.aps.set_ylabel(**self.ylps)
>         self.aps.redraw_in_frame()
>         self.canvasps.blit()
> # end
> 
> I don't know if it is a bug or something else but thank you in advance if you 
> can help me.
> 
> Jonathan
> 
> 
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge  
> This is your chance to win up to $100,000 in prizes! For a limited time, 
> vendors submitting new applications to BlackBerry App World(TM) will have 
> the opportunity to enter the BlackBerry Developer Challenge. See full prize 
> details at: http://p.sf.net/sfu/blackberry


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to