pylab, twinx, and displayed coordinates

Paul Ivanov wrote:

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)

Hmm. I do not get a reversed list of axes. This is the output of
the example code below:

[<matplotlib.axes.AxesSubplot object at 0x8d8fb4c>, <matplotlib.axes.Axes object at 0x8f633ec>]
[<matplotlib.axes.AxesSubplot object at 0x8d8fb4c>, <matplotlib.axes.Axes object at 0x8f633ec>]

BTW, what's matplotlib.axes.AxesSubplot? I couldn't find this class.

Ciao
Andreas

import pylab as mpl

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

f = mpl.gcf()

print f.axes

f.axes[0].set_frame_on(False)
f.axes.reverse()
f.axes[0].set_frame_on(True)

print f.axes

mpl.show()

···

On Fri, Sep 23, 2011 at 2:08 PM, Andreas Matthias > <andreas.matthias@...287...> wrote:

Hmm. I do not get a reversed list of axes. This is the output of
the example code below:

[<matplotlib.axes.AxesSubplot object at 0x8d8fb4c>, <matplotlib.axes.Axes object at 0x8f633ec>]
[<matplotlib.axes.AxesSubplot object at 0x8d8fb4c>, <matplotlib.axes.Axes object at 0x8f633ec>]

This doesn't seem right - for me that code results in:
[<matplotlib.axes.AxesSubplot object at 0x16d7de70>,
<matplotlib.axes.Axes object at 0x1b77c890>]
[<matplotlib.axes.Axes object at 0x1b77c890>,
<matplotlib.axes.AxesSubplot object at 0x16d7de70>]

can you try explicitly swapping your axes? f.axes =
[f.axes[1],f.axes[0]] instead of the call to reverse?

BTW, what's matplotlib.axes.AxesSubplot? I couldn't find this class.

see SubplotBase class and subplot_class_factory function in matplotlib/axes.py

best,

···

On Sat, Sep 24, 2011 at 3:59 AM, 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