pylab, twinx, and displayed coordinates

In the following example the coordinates of the mouse
cursor displayed in the pylab window belong to the
second y-axis. But I would prefer to have the coordinates
of the first y-axis to be displayed. Is this possible?

import pylab as mpl

mpl.plot([1,3,2])
mpl.twinx()
mpl.plot([400,50,100])
mpl.show()

Ciao
Andreas

Hi Andreas,

In the following example the coordinates of the mouse
cursor displayed in the pylab window belong to the
second y-axis. But I would prefer to have the coordinates
of the first y-axis to be displayed. Is this possible?

yes it is.

import pylab as mpl

mpl.plot([1,3,2])
mpl.twinx()
mpl.plot([400,50,100])
mpl.show()

# get the current figure
f = mpl.gcf()

# Hide the "background" for the first axes, otherwise it will block
the second one when we swap
f.axes[0].set_frame_on(False)

# Swap the axes
f.axes.reverse()

# Turn on the "background" for the *new* first axes (the one that was
created second)
f.axes[0].set_frame_on(False)

you can also achieve the same effect by changing the zorder of axes -
provided that you remember to have turn the frame on for the one that
is the furthest back, and turn it off for all others lying on top of
it. You can see what happens if you don't do this by omitting the
calls to set_frame_on, and then verifying that the second line does
not show up (because the original axes' frame patch is blocking it.

best,

ยทยทยท

On Fri, Sep 23, 2011 at 2:08 PM, Andreas Matthias <andreas.matthias@...287...> wrote:
--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7