|
From: Andreas M. <and...@gm...> - 2011-09-23 21:10:33
|
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 |
|
From: Paul I. <piv...@gm...> - 2011-09-24 06:12:40
|
Hi Andreas, On Fri, Sep 23, 2011 at 2:08 PM, Andreas Matthias <and...@gm...> 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) 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, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |
|
From: Andreas M. <and...@gm...> - 2011-09-24 11:00:29
|
Paul Ivanov wrote: > On Fri, Sep 23, 2011 at 2:08 PM, Andreas Matthias > <and...@gm...> 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() |
|
From: Paul I. <piv...@gm...> - 2011-09-25 06:27:01
|
On Sat, Sep 24, 2011 at 3:59 AM, Andreas Matthias <and...@gm...> 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, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |
|
From: Andreas M. <and...@gm...> - 2011-09-25 11:50:31
|
Paul Ivanov wrote:
> On Sat, Sep 24, 2011 at 3:59 AM, Andreas Matthias
> <and...@gm...> 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?
Traceback (most recent call last):
File "t5.py", line 13, in <module>
f.axes = [f.axes[1],f.axes[0]]
AttributeError: can't set attribute
I've tried it with matplotlib 1.0.1 and 1.1.0. Same error message.
Python is 2.6.4.
I'm stumped ...
Ciao
Andreas
|
|
From: Benjamin R. <ben...@ou...> - 2011-09-25 16:07:33
|
On Sunday, September 25, 2011, Andreas Matthias <and...@gm...> wrote: > Paul Ivanov wrote: > >> On Sat, Sep 24, 2011 at 3:59 AM, Andreas Matthias >> <and...@gm...> 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? > > Traceback (most recent call last): > File "t5.py", line 13, in <module> > f.axes = [f.axes[1],f.axes[0]] > AttributeError: can't set attribute > > > I've tried it with matplotlib 1.0.1 and 1.1.0. Same error message. > Python is 2.6.4. > I'm stumped ... > > > Ciao > Andreas > Sometimes installations can get mixed up. What does: Import matplotlib print matplotlib.__version__ print matplotlib.__file__ outputs for your v1.1.0 installation and your v1.0.1 install? Ben Root |
|
From: Andreas M. <and...@gm...> - 2011-09-25 16:25:36
|
Benjamin Root wrote: > On Sunday, September 25, 2011, Andreas Matthias <and...@gm...> > wrote: >> Paul Ivanov wrote: >> >>> On Sat, Sep 24, 2011 at 3:59 AM, Andreas Matthias >>> <and...@gm...> 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? >> >> Traceback (most recent call last): >> File "t5.py", line 13, in <module> >> f.axes = [f.axes[1],f.axes[0]] >> AttributeError: can't set attribute >> >> >> I've tried it with matplotlib 1.0.1 and 1.1.0. Same error message. >> Python is 2.6.4. >> I'm stumped ... > > Sometimes installations can get mixed up. What does: > > Import matplotlib > print matplotlib.__version__ > print matplotlib.__file__ > > outputs for your v1.1.0 installation and your v1.0.1 install? 1.1.0 /home/andreas/local/python/lib/python2.6/site-packages/matplotlib/__init__.pyc This is the right place. Then I removed matplotlib/ and installed it again. But the error stays the same. Ciao Andreas |