Manuel Metz wrote:
Paul Smith wrote:
I'm plotting two curves in one subplot with twinx to allow different y
scales. The script below is an example. When zooming in using
zoom-to-rect on Tk's navigation toolbar2 (TkAgg is my backend) I think
the x axis part of the zoom is happening twice. Rubberbanding the
example from x=20 to 80 results in a zoomed x range of about 32 to 68,
which is about what you'd expect for zooming with the same range twice.
Is there a way of restricting this to only one zoom?
Paul
------------
from pylab import *
f=figure(1)
ax1=f.add_subplot(111)
ax1.plot(arange(100))
ax2=twinx(ax1)
ax2.plot(-arange(100),'g')
draw()
Hi,
there was the above mail on the users list.
The problem is that "release_zoom" in backend_bases.py is called twice
in the above case if zoomed to a twinx'ed plot. One way to fix this
behavior is to set a "twin" attribute to the axes instance. Attached is
a patch against the 0.91 trunk.
John: is this okay or is there a better way to fix the problem?
Manuel
Ups - the last patch didn't work correctly since the y-axis of the
twin'ed plot wasn't scaled correctly. So I try it again ;-)
Manuel
Index: backend_bases.py
===================================================================
--- backend_bases.py (revision 5029)
+++ backend_bases.py (working copy)
@@ -1710,28 +1710,34 @@
x, y = a.transData.inverse_xy_tup( (x, y) )
Xmin,Xmax=a.get_xlim()
Ymin,Ymax=a.get_ylim()
-
- if Xmin < Xmax:
- if x<lastx: xmin, xmax = x, lastx
- else: xmin, xmax = lastx, x
- if xmin < Xmin: xmin=Xmin
- if xmax > Xmax: xmax=Xmax
+
+ if not a._twinx:
+ if Xmin < Xmax:
+ if x<lastx: xmin, xmax = x, lastx
+ else: xmin, xmax = lastx, x
+ if xmin < Xmin: xmin=Xmin
+ if xmax > Xmax: xmax=Xmax
+ else:
+ if x>lastx: xmin, xmax = x, lastx
+ else: xmin, xmax = lastx, x
+ if xmin > Xmin: xmin=Xmin
+ if xmax < Xmax: xmax=Xmax
else:
- if x>lastx: xmin, xmax = x, lastx
- else: xmin, xmax = lastx, x
- if xmin > Xmin: xmin=Xmin
- if xmax < Xmax: xmax=Xmax
+ xmin, xmax = Xmin, Xmax
- if Ymin < Ymax:
- if y<lasty: ymin, ymax = y, lasty
- else: ymin, ymax = lasty, y
- if ymin < Ymin: ymin=Ymin
- if ymax > Ymax: ymax=Ymax
+ if not a._twiny:
+ if Ymin < Ymax:
+ if y<lasty: ymin, ymax = y, lasty
+ else: ymin, ymax = lasty, y
+ if ymin < Ymin: ymin=Ymin
+ if ymax > Ymax: ymax=Ymax
+ else:
+ if y>lasty: ymin, ymax = y, lasty
+ else: ymin, ymax = lasty, y
+ if ymin > Ymin: ymin=Ymin
+ if ymax < Ymax: ymax=Ymax
else:
- if y>lasty: ymin, ymax = y, lasty
- else: ymin, ymax = lasty, y
- if ymin > Ymin: ymin=Ymin
- if ymax < Ymax: ymax=Ymax
+ ymin, ymax = Ymin, Ymax
if self._button_pressed == 1:
a.set_xlim((xmin, xmax))
Index: axes.py
===================================================================
--- axes.py (revision 5029)
+++ axes.py (working copy)
@@ -447,6 +447,8 @@
sharex=None, # use Axes instance's xaxis info
sharey=None, # use Axes instance's yaxis info
label='',
+ twinx=False,
+ twiny=False,
**kwargs
):
"""
@@ -500,6 +502,11 @@
self._mastery = False
if sharex: sharex._masterx = True
if sharey: sharey._mastery = True
+ #
+ self._twinx = False
+ self._twiny = False
+ if twinx: self._twinx = True
+ if twiny: self._twiny = True
self.set_label(label)
self.set_figure(fig)
@@ -5010,7 +5017,8 @@
right
"""
- ax2 = self.figure.add_axes(self.get_position(), sharex=self, frameon=False)
+ ax2 = self.figure.add_axes(self.get_position(), sharex=self, frameon=False,
+ twinx=True)
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position('right')
self.yaxis.tick_left()
@@ -5026,7 +5034,8 @@
top
"""
- ax2 = self.figure.add_axes(self.get_position(), sharey=self, frameon=False)
+ ax2 = self.figure.add_axes(self.get_position(), sharey=self, frameon=False,
+ twiny=True)
ax2.xaxis.tick_top()
ax2.xaxis.set_label_position('top')
self.xaxis.tick_bottom()
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel