Daniele,

I agree this is perhaps a little overly complicated. (However, once you
figure it out, it does give you a ton of flexibility.)  I played around
with this a bit (thanks IPython!), and I may have figured out what you
wanted to do. I rewrote the example you linked from the MPL website. I
couldn't simplify it much, but it does change the size, location and labels
of the floating y axis.

#################

from mpl_toolkits.axes_grid1 import host_subplot

import mpl_toolkits.axisartist as AA

import matplotlib.pyplot as plt


host = host_subplot(111, axes_class=AA.Axes)

plt.subplots_adjust(right=0.75)


par1 = host.twinx()


par2 = host.twinx()

offset = 60

new_fixed_axis = par2.get_grid_helper().new_fixed_axis

par2.axis["right"] = new_fixed_axis(loc="right",

axes=par2,

offset=(offset, 0))

par2.axis["right"].toggle(all=True)


p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")

p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")

p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")


host.legend()


host.set_xlabel("Distance")

host.set_ylabel("Density")

host.axis["left"].label.set_color(p1.get_color())

host.set_xlim(0, 2)

host.set_ylim(0, 2)


par1.set_ylabel("Temperature")

par1.axis["right"].label.set_color(p2.get_color())

par1.set_ylim(0, 4)


par2.set_ylabel("Velocity")

par2.set_ylim(1, 65)

par2.yaxis.set_ticks( (20.0, 40.0) )

par2.yaxis.set_ticklabels( ('A', 'B') )

par2.axis["right"].label.set_color(p3.get_color())

par2.axis["right"].label.set_fontsize(18)

par2.axis["right"].major_ticklabels.set_fontsize(14)


plt.show()

##################


Hope that helps.


Ryan


On Tue, Oct 29, 2013 at 5:54 AM, Daniele Nicolodi <dani...@grinta.net>wrote:

> On 29/10/2013 03:11, Ryan Nelson wrote:
> > Daniele,
> >
> > I noticed the same problem with the Qt backend. However, I was looking
> > at the documentation on the AxesGrid webpage here:
> > http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html
> > And I see the following warning:
> >
> > axes_grid and axisartist (but not axes_grid1) uses a custom Axes class
> > (derived from the mpl’s original Axes class). As a side effect, some
> > commands (mostly tick-related) do not work. Use axes_grid1 to avoid
> > this, or see how things are different in axes_grid and axisartist (LINK
> > needed)
> >
> > Unfortunately, no link. But perhaps there is a way to avoid using the
> > Axes class from axisartist in your use case. For example, could you
> > import the Axes class as follows:
> >
> > from matplotlib.axes import Axes
> >
> > That seems to work with the Qt and PDF backends on Windows 7 (Anaconda
> > Python).
>
> Hello Ryan,
>
> thanks for confirming the problem.  I've also seen that note, but I
> thought "do not work" means that the methods raise an exception, not
> that they arbitrarily ignore arguments :(
>
> While the standard Axis class works for the cut-down example I posted,
> it does not for what I'm trying to achieve (having a second x axis below
> the main one).  I came up with that solution following the matplotlib
> documentation:
>
>
> http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axisartist-with-parasiteaxes
>
> however I don't really understand why some of the contortions there are
> necessary (they are not explained in the documentation).
>
> Cheers,
> Daniele
>
>
>
> ------------------------------------------------------------------------------
> Android is increasing in popularity, but the open development platform that
> developers love is also attractive to malware creators. Download this white
> paper to learn more about secure code signing practices that can help keep
> Android apps secure.
> http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to