Reworked axis('scaled')

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

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

...
def release_zoom(...):

    ...
       # single click: 5 pixels is a threshold
        if abs(x-lastx)<5 or abs(y-lasty)<5:

            lastx, lasty = a.transData.inverse_xy_tup( (lastx, lasty) )
            x, y = a.transData.inverse_xy_tup
( (x, y) )
            Xmin,Xmax=a.get_xlim()
            Ymin,Ymax=a.get_ylim()

            if self._button_pressed == 1:

                # zoom in by 20%, make point clicked center
                dx=(Xmax-Xmin)*
0.8*0.5
                dy=(Ymax-Ymin)*0.8*0.5
                a.set_xlim((x-dx, x+dx))
                a.set_ylim((y-dy, y+dy))
               
            elif self._button_pressed == 3:
               
                # zoom out by 20%, make point clicked center
                dx=(Xmax-Xmin)*1.2*0.5
                dy=(Ymax-Ymin)*1.2*0.5
                a.set_xlim((x-dx, x+dx))
                a.set_ylim
((y-dy, y+dy))

            self.draw()
            self._xypress = None
            self._button_pressed == None

            self.push_current()
            self.release(event)          
            return

   # zoom to rect
  ...
···

On 10/14/05, Mark Bakker <markbak@…120…287…> 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.

Helge and others -

I really like Helge's idea to zoom by 20% in Toolbar2 if you click once only.
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 <helgea@...287...> wrote:

On 10/14/05, Mark Bakker <markbak@...287...> 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 = a.transData.inverse_xy_tup( (lastx, lasty) )
            x, y = a.transData.inverse_xy_tup ( (x, y) )
            Xmin,Xmax=a.get_xlim()
            Ymin,Ymax=a.get_ylim()

            if self._button_pressed == 1:

                # zoom in by 20%, make point clicked center
                dx=(Xmax-Xmin)* 0.8*0.5
                dy=(Ymax-Ymin)*0.8*0.5
                a.set_xlim((x-dx, x+dx))
                a.set_ylim((y-dy, y+dy))

            elif self._button_pressed == 3:

                # zoom out by 20%, make point clicked center
                dx=(Xmax-Xmin)*1.2*0.5
                dy=(Ymax-Ymin)*1.2*0.5
                a.set_xlim((x-dx, x+dx))
                a.set_ylim ((y-dy, y+dy))

            self.draw()
            self._xypress = None
            self._button_pressed == None

            self.push_current()
            self.release(event)
            return

   # zoom to rect
  ...
</pre>