Two Scale Problem with ticks on secondary axis?

When I run the example for two scales (two_scales.py), the

    > secondary axis - on the right- has ticks for both
    > scales. The primary - on left - has the expected one set of
    > ticks. I did modify the example code as shown
    > below. Instead of calling the twinx function of pylab I
    > explicitly took the code from pylab.py. this was because I
    > wanted to see exactly what was being done with an intent to
    > modify it slightly. In any case it should be completely
    > equivalent to the example. When I did run the example
    > unchanged it gave the same result.

    > Is this a bug or something I am missing something ?

Looks like a bug -- I see the same thing with twinx. Could you file
this one of the sf site? I took a look through the axis code but
couldn't find the culprit. I'm CC Baptiste who wrote the code --
maybe he has some insight.

Thanks

···

Running matplotlib 0.84 on OS X 10.3.9

    > import pylab import Numeric N = Numeric PL = pylab

    > ax1 = PL.subplot(111) t = N.arange(0.01, 10.0, 0.01) s1 =
    > N.exp(t) PL.plot(t, s1, 'b-') PL.xlabel('time (s)')
    > PL.ylabel('exp') # turn off the 2nd axes rectangle with
    > frameon kwarg #ax2 = PL.twinx() ax = PL.gca() ax2 =
    > PL.gcf().add_axes(ax.get_position(), sharex=ax,
    > frameon=False) ax2.yaxis.tick_right()
    > ax2.yaxis.set_label_position('right')

    > s2 = N.sin(2*N.pi*t) PL.plot(t, s2, 'r.') PL.ylabel('sin')
    > ax2.yaxis.tick_right() show()

    > -------------------------------------------------------
    > This SF.Net email is sponsored by: Power Architecture
    > Resource Center: Free content, downloads, discussions, and
    > more. http://solutions.newsforge.com/ibmarch.tmpl
    > _______________________________________________
    > Matplotlib-users mailing list
    > Matplotlib-users@lists.sourceforge.net
    > matplotlib-users List Signup and Options

Looks like a bug -- I see the same thing with twinx. Could you file
this one of the sf site? I took a look through the axis code but
couldn't find the culprit. I'm CC Baptiste who wrote the code --
maybe he has some insight.

It is indeed a bug. Imho we should fix it in pylab.py, by changing the
function twinx to read:

def twinx(ax=None):
    """
    Make a second axes overlay ax (or the current axes if ax is None)
    sharing the xaxis. The ticks for ax2 will be placed on the right,
    and the ax2 instance is returned. See examples/two_scales.py
    """
    if ax is None:
        ax=gca()

    ax2 = gcf().add_axes(ax.get_position(), sharex=ax, frameon=False)
    ax2.yaxis.tick_right()
    ax2.yaxis.set_label_position('right')

    ax.yaxis.tick_left()

    draw_if_interactive()
    return ax2

The attached one-line patch does the trick.

Cheers, Baptiste

pylab.py.diff (279 Bytes)