Hi,

The code below should create a properly placed 2nd x-axis. You might need to
adjust the placement of the figure canvas to match into the window.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost

fig = plt.figure(figsize=(10,8))
host = SubplotHost(fig, 111)
fig.add_subplot(host)
parx = host.twiny()

parx.axis["top"].set_visible(False)
offset = 0, -50
new_axisline = parx.get_grid_helper().new_fixed_axis
parx.axis["bottom"] = new_axisline(loc="bottom", axes=parx, offset=offset)
parx.axis["bottom"].label.set_visible(True)

hplt, = host.plot(np.random.rand(100))
p2, = parx.plot(np.linspace(0,20,100), np.random.rand(100)*5.0,
color='green')

plt.show()


There is also another example at:
http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#axisartist-with-parasiteaxes

Hope this helps.

On Fri, Sep 9, 2011 at 12:50 PM, Neal Becker <ndbeck...@gmail.com> wrote:

> Neal Becker wrote:
>
> > I have a semilog plot.  I'd like to add a second x axis (maybe below the
> > existing one, or else maybe on top of graph).  This second x axis is
> simply
> > describing the same existing data, in different units.
> >
> > For example imagine a plot of
> >
> > x - time in seconds
> > y - velocity
> >
> > x2 - time in minutes
> >
> >
>
> This almost works:
>    fig = plt.figure()
>    ax = fig.add_subplot(111)
> ...
>    ax2 = ax.twiny()
>    min_x, max_x = ax.get_xlim()
>    ax2.set_xlim (min_x-1, max_x-1)
>
> except the 2nd x axis is on the top, and prints right on top of the title
>
>
>
> ------------------------------------------------------------------------------
> Why Cloud-Based Security and Archiving Make Sense
> Osterman Research conducted this study that outlines how and why cloud
> computing security and archiving is rapidly being adopted across the IT
> space for its ease of implementation, lower cost, and increased
> reliability. Learn more. http://www.accelacomm.com/jaw/sfnl/114/51425301/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>



-- 
Gökhan
------------------------------------------------------------------------------
Why Cloud-Based Security and Archiving Make Sense
Osterman Research conducted this study that outlines how and why cloud
computing security and archiving is rapidly being adopted across the IT 
space for its ease of implementation, lower cost, and increased 
reliability. Learn more. http://www.accelacomm.com/jaw/sfnl/114/51425301/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to