From: Mark B. <ma...@gm...> - 2005-10-14 20:59:34
|
Hello all - I finally found time to fix the axis('scaled') feature. It is now consistent when zooming, as requested. In essence, it works the same as axis('equal'), but fixes the lower-left-hand corner rather than the center of the subplot. When using axis('scaled') the _autoscaleon is set to False, so that axis limits will be fixed when features are added to the figure. You can overwrite this by setting it the regular way (also works for axis('equal')) ax.set_autoscale_on(False). My last modification is a prototype implementation of zooming when two axes are linked. The idea behind this is that when an axis is 'equal' or 'scaled' and another axis is linked to this axis, that when you are zooming and changing the size of the subplot, then the size of the linkes axis should change accordingly. I use this when I am contouring 2D horizontal data and have a vertical cross-section linked to the x-axis of the horizontal plot. When I zoom in on the horizontal plot, the length of the linked axis now gets changes too! Works great, actually, but has been implemented for linked x-axis only for now. It works when zooming in the horizontal data (which has axis 'equal'), but not yet when zooming in the linked vertical cross-section. Still working on it. Anyway, I modified 3 files, which I submitted on the patches page. If anybody is interested, download these and let me know what you think. I presume they'll get implemented in CVS when John or others find the time to do so. Mark |
From: Helge A. <he...@gm...> - 2005-10-17 15:44:03
|
On 10/14/05, Mark Bakker <ma...@gm...> wrote: > > Hello all - > > I finally found time to fix the axis('scaled') feature. > It is now consistent when zooming, as requested. > In essence, it works the same as axis('equal'), but fixes the > lower-left-hand corner rather than the center of the > subplot. When using axis('scaled') the _autoscaleon is > set to False, so that axis limits will be fixed when > features are added to the figure. You can overwrite this > by setting it the regular way (also works for axis('equal')) > ax.set_autoscale_on(False). > > My last modification is a prototype implementation of > zooming when two axes are linked. The idea behind this > is that when an axis is 'equal' or 'scaled' and another > axis is linked to this axis, that when you are zooming and > changing the size of the subplot, then the size of the > linkes axis should change accordingly. I use this when > I am contouring 2D horizontal data and have a vertical > cross-section linked to the x-axis of the horizontal plot. > When I zoom in on the horizontal plot, the length of the > linked axis now gets changes too! Works great, actually, > but has been implemented for linked x-axis only for now. > It works when zooming in the horizontal data (which > has axis 'equal'), but not yet when zooming in the > linked vertical cross-section. Still working on it. Hi, yes this is a step in the right direction! IMO it would also be nice with functionality for zooming in/out on single clicks with the left and right button, e.g. something like the below for backend_bases.py: (hope it is not wrapped to death...) Helge <pre> ... def release_zoom(...): ... # single click: 5 pixels is a threshold if abs(x-lastx)<5 or abs(y-lasty)<5: lastx, lasty =3D a.transData.inverse_xy_tup( (lastx, lasty) ) x, y =3D a.transData.inverse_xy_tup( (x, y) ) Xmin,Xmax=3Da.get_xlim() Ymin,Ymax=3Da.get_ylim() if self._button_pressed =3D=3D 1: # zoom in by 20%, make point clicked center dx=3D(Xmax-Xmin)*0.8*0.5 dy=3D(Ymax-Ymin)*0.8*0.5 a.set_xlim((x-dx, x+dx)) a.set_ylim((y-dy, y+dy)) elif self._button_pressed =3D=3D 3: # zoom out by 20%, make point clicked center dx=3D(Xmax-Xmin)*1.2*0.5 dy=3D(Ymax-Ymin)*1.2*0.5 a.set_xlim((x-dx, x+dx)) a.set_ylim((y-dy, y+dy)) self.draw() self._xypress =3D None self._button_pressed =3D=3D None self.push_current() self.release(event) return # zoom to rect ... </pre> |
From: Mark B. <ma...@gm...> - 2005-10-18 17:21:22
|
Helge and others - I really like Helge's idea to zoom by 20% in Toolbar2 if you click once onl= y. Will even try to center it near the click if possible. Will try to implement a version of her code this week. Incidentally, I found a bug and an inconsistency in my axis('scaled') implementation. The new pylab file on the patches page is fixed. Mark On 10/17/05, Helge Avlesen <he...@gm...> wrote: > > > > On 10/14/05, Mark Bakker <ma...@gm...> wrote: > > Hello all - > > > > I finally found time to fix the axis('scaled') feature. > > It is now consistent when zooming, as requested. > > In essence, it works the same as axis('equal'), but fixes the > > lower-left-hand corner rather than the center of the > > subplot. When using axis('scaled') the _autoscaleon is > > set to False, so that axis limits will be fixed when > > features are added to the figure. You can overwrite this > > by setting it the regular way (also works for axis('equal')) > > ax.set_autoscale_on(False). > > > > My last modification is a prototype implementation of > > zooming when two axes are linked. The idea behind this > > is that when an axis is 'equal' or 'scaled' and another > > axis is linked to this axis, that when you are zooming and > > changing the size of the subplot, then the size of the > > linkes axis should change accordingly. I use this when > > I am contouring 2D horizontal data and have a vertical > > cross-section linked to the x-axis of the horizontal plot. > > When I zoom in on the horizontal plot, the length of the > > linked axis now gets changes too! Works great, actually, > > but has been implemented for linked x-axis only for now. > > It works when zooming in the horizontal data (which > > has axis 'equal'), but not yet when zooming in the > > linked vertical cross-section. Still working on it. > > > Hi, > yes this is a step in the right direction! IMO it would also be nice wit= h > functionality for > zooming in/out on single clicks with the left and right button, e.g. > something like the below for backend_bases.py: (hope it is not wrapped t= o > death...) > > Helge > > > <pre> > ... > def release_zoom(...): > ... > # single click: 5 pixels is a threshold > if abs(x-lastx)<5 or abs(y-lasty)<5: > > lastx, lasty =3D a.transData.inverse_xy_tup( (lastx, lasty) ) > x, y =3D a.transData.inverse_xy_tup ( (x, y) ) > Xmin,Xmax=3Da.get_xlim() > Ymin,Ymax=3Da.get_ylim() > > if self._button_pressed =3D=3D 1: > > # zoom in by 20%, make point clicked center > dx=3D(Xmax-Xmin)* 0.8*0.5 > dy=3D(Ymax-Ymin)*0.8*0.5 > a.set_xlim((x-dx, x+dx)) > a.set_ylim((y-dy, y+dy)) > > elif self._button_pressed =3D=3D 3: > > # zoom out by 20%, make point clicked center > dx=3D(Xmax-Xmin)*1.2*0.5 > dy=3D(Ymax-Ymin)*1.2*0.5 > a.set_xlim((x-dx, x+dx)) > a.set_ylim ((y-dy, y+dy)) > > self.draw() > self._xypress =3D None > self._button_pressed =3D=3D None > > self.push_current() > self.release(event) > return > > # zoom to rect > ... > </pre> > > > > |