twin / dual / two axis seems to confuse or break toolbar magnifier

I am trying to code an application with two checkboxes, one associated with
each axis on a simple plot. I can then turn on and off lines in the plot
that are scaled either to the left side or right side of the plot.

This is working fine and patterned after some of the examples from
matplotlib.

However, when I use the toolbar feature with the "magnifier" the scaling is
not usually correct. More specifically, if I select an area with the
magnifier, the next drawing of the information is not scaled right.
(ususally it is a smaller subset of the data selected)

I have confirmed when I run without twinx , the magnifier works fine.

I also have noticed that when running the example from matplotlib the same
thing happens. I have searched a bit looking for perhaps a bug or comment in
forums on how to workaround this or perhaps I have done something wrong, but
no luck. Perhaps I don't understand how the magnifier is supposed to work
but when I disable the twinx capability of my code, things seem to work
fine. (I'm still mostly a noob but I am persistent.)

I believe I have 0.90 or perhaps one earlier. I wasn't completely sure how
to check but 0.90 is shown in the __init__.py file.

I have attached the matplotlib provided example that I feel doesn't work
right. I also have a snippet of my code below. (which is structured a bit
different than the example but when I run identical to the snippet, using
the structure of my code I get an error due to twinx not being a method of
subplot - as I recall)

from two scales example provided with matplotlib

from pylab import *

ax1 = subplot(111)
t = arange(0.01, 10.0, 0.01)
s1 = exp(t)
plot(t, s1, 'b-')
xlabel('time (s)')
ylabel('exp')

# turn off the 2nd axes rectangle with frameon kwarg
ax2 = twinx()
s2 = sin(2*pi*t)
plot(t, s2, 'r.')
ylabel('sin')
ax2.yaxis.tick_right()
show()

snippet from my code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

        self.axL=subplot(132, position=[0.2,0.1,0.6,0.8])
        self.axR=twinx(self.axL)
        self.rax1=subplot(131, position=[0.01, 0.10, 0.14, 0.8])
        self.rax2=subplot(133, position=[0.85, 0.10, 0.14, 0.8])
            
        for key in sorted(dict):
            if dict[key][1]<>'N': #~ providing key to allow for skipping
data set
                visibility=dict[key][2]
                exec("self.l%s, =
self.ax%s.plot(glbl.fusdata%s,visible=visibility,ls=dict[key][4],color=dict[key][3])"%
(key,dict[key][1],key))

···


View this message in context: http://www.nabble.com/twin---dual---two-axis-seems-to-confuse-or-break-toolbar-magnifier-tp20256700p20256700.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Can you be more specific about what is going wrong? The zoom magnifier seems to work fine for me with or without twinx, but perhaps we just have different expectations of how it works. Could you perhaps provide screenshots?

I'm checking against SVN trunk. I didn't check against 0.90.1, since it would require installing an older version of numpy, and other dependency dances etc. But I'm happy to dig further once I have a better idea of what is going wrong for you.

This FAQ explains how to get the version number and other useful information for a bug report:

http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#report-a-problem

Cheers,
Mike

wet_colored)arch wrote:

···

I am trying to code an application with two checkboxes, one associated with
each axis on a simple plot. I can then turn on and off lines in the plot
that are scaled either to the left side or right side of the plot.

This is working fine and patterned after some of the examples from
matplotlib.

However, when I use the toolbar feature with the "magnifier" the scaling is
not usually correct. More specifically, if I select an area with the
magnifier, the next drawing of the information is not scaled right. (ususally it is a smaller subset of the data selected)

I have confirmed when I run without twinx , the magnifier works fine.

I also have noticed that when running the example from matplotlib the same
thing happens. I have searched a bit looking for perhaps a bug or comment in
forums on how to workaround this or perhaps I have done something wrong, but
no luck. Perhaps I don't understand how the magnifier is supposed to work
but when I disable the twinx capability of my code, things seem to work
fine. (I'm still mostly a noob but I am persistent.)

I believe I have 0.90 or perhaps one earlier. I wasn't completely sure how
to check but 0.90 is shown in the __init__.py file.

I have attached the matplotlib provided example that I feel doesn't work
right. I also have a snippet of my code below. (which is structured a bit
different than the example but when I run identical to the snippet, using
the structure of my code I get an error due to twinx not being a method of
subplot - as I recall)

from two scales example provided with matplotlib
  
from pylab import *

ax1 = subplot(111)
t = arange(0.01, 10.0, 0.01)
s1 = exp(t)
plot(t, s1, 'b-')
xlabel('time (s)')
ylabel('exp')

# turn off the 2nd axes rectangle with frameon kwarg
ax2 = twinx()
s2 = sin(2*pi*t)
plot(t, s2, 'r.')
ylabel('sin')
ax2.yaxis.tick_right()
show()

snippet from my code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

        self.axL=subplot(132, position=[0.2,0.1,0.6,0.8])
        self.axR=twinx(self.axL)
        self.rax1=subplot(131, position=[0.01, 0.10, 0.14, 0.8])
        self.rax2=subplot(133, position=[0.85, 0.10, 0.14, 0.8])
                    for key in sorted(dict):
            if dict[key][1]<>'N': #~ providing key to allow for skipping
data set
                visibility=dict[key][2]
                exec("self.l%s, =
self.ax%s.plot(glbl.fusdata%s,visible=visibility,ls=dict[key][4],color=dict[key][3])"%
(key,dict[key][1],key))
        
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Note that only one of the two axes can get the events, and that is
determined by the axes zorder. So if you want ax1 to get the events

  ax1 = fig.add_subplot(111)
  ax1t = ax1.twinx()
  ax1.set_zorder(10)
  ax1t.set_zorder(1)

JDH

···

On Tue, Nov 4, 2008 at 7:29 AM, Michael Droettboom <mdroe@...86...> wrote:

Can you be more specific about what is going wrong? The zoom magnifier
seems to work fine for me with or without twinx, but perhaps we just
have different expectations of how it works. Could you perhaps provide
screenshots?

Can you be more specific about what is going wrong? The zoom magnifier
seems to work fine for me with or without twinx, but perhaps we just
have different expectations of how it works. Could you perhaps provide
screenshots?

I confirmed it is 0.90.0 (I am running on Windows)
attached is code (which is simply example packaged with matplot lib)

ALSO:

the default figure: of which I selected the region from 2-4 on the x-axis
for magnifying
the resulting figure from magnifying: you can see much of the content from
2-4 is missing (I selected the entire y axis with the magnifier) -- the
xaxis is only selecting a subset of the range I chose
the expected figure: I used the crossed arrows instead of the magnifier to
create a plot figure that roughly mimics what I expected... I expected to
see all data in y from x = 2 to 4

Is my expectation wrong? I expect the x and y axis range selected by the
magnifier tool to be fully represented in the subsequent representation of
the data - it always seems to be subset of the data range chosen.

http://www.nabble.com/file/p20334562/two_scales.py two_scales.py
http://www.nabble.com/file/p20334562/two_scales_baseline.png
two_scales_baseline.png
http://www.nabble.com/file/p20334562/two_scales_2to4_concern.png
two_scales_2to4_concern.png
http://www.nabble.com/file/p20334562/two_scales_2to4_expectation.png
two_scales_2to4_expectation.png

···


View this message in context: http://www.nabble.com/twin---dual---two-axis-seems-to-confuse-or-break-toolbar-magnifier-tp20256700p20334562.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Thanks for the re-explanation. I can confirm that this is broken as recently as 0.91.2. However, it works as expected with a recent SVN trunk, and matplotlib 0.98.3.

It seems what this is doing is adjusting the limits twice (for each of the twin axes), the first correctly, and then again by applying the same rectangle to the adjusted limits.

I will go ahead and fix this on the 0.91.x maintenance branch. (It seems Sourceforge's SVN is down at the moment, so I can't right now).

I've also attached a patch that *may* apply to 0.90.0. It's a lot of work for me to move back to that version to test given the change in Numpy dependencies etc. If the patch doesn't work for you, you may just want to consider upgrading to the most recent 0.98.x.

Cheers,
Mike

wet_colored)arch wrote:

twinx_zoom_rectangle.diff (929 Bytes)

···

Can you be more specific about what is going wrong? The zoom magnifier seems to work fine for me with or without twinx, but perhaps we just have different expectations of how it works. Could you perhaps provide screenshots?

>>
I confirmed it is 0.90.0 (I am running on Windows)
attached is code (which is simply example packaged with matplot lib)

ALSO:

the default figure: of which I selected the region from 2-4 on the x-axis
for magnifying
the resulting figure from magnifying: you can see much of the content from
2-4 is missing (I selected the entire y axis with the magnifier) -- the
xaxis is only selecting a subset of the range I chose
the expected figure: I used the crossed arrows instead of the magnifier to
create a plot figure that roughly mimics what I expected... I expected to
see all data in y from x = 2 to 4

Is my expectation wrong? I expect the x and y axis range selected by the
magnifier tool to be fully represented in the subsequent representation of
the data - it always seems to be subset of the data range chosen.

http://www.nabble.com/file/p20334562/two_scales.py two_scales.py http://www.nabble.com/file/p20334562/two_scales_baseline.png
two_scales_baseline.png http://www.nabble.com/file/p20334562/two_scales_2to4_concern.png
two_scales_2to4_concern.png http://www.nabble.com/file/p20334562/two_scales_2to4_expectation.png
two_scales_2to4_expectation.png
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA