Hi,
I just noticed a bug in twinx/twiny in axes.py. twinx has:
ax2 = self.figure.add_axes(self.get_position(True), # sharex=self,
frameon=False)
while twiny has:
ax2 = self.figure.add_axes(self.get_position(True), sharey=self,
frameon=False)
Therefore twiny will share the y axis, while twinx will not share the x
axis. I am not sure what the "desired" behavior is, but one has to be
wrong. As the principle use for this is making plots of two curves
sharing one axis, but different in the other, I imagine that the twiny
behavior is the desired one. If not, then the following doesn't look
quite right:
from numpy import *
from matplotlib.pylab import *
x = linspace(0,pi,20)
y = sin(x)
x2 = x + 0.1 * randn(*x.shape)
y2 = 10 + y + 0.1 * randn(*y.shape)
a1 = gca()
plot(x,y)
a2 = twinx()
plot(x2,y2, 'o')
The pylab_examples/two_scales.py only works because the two curves have
identical x values.
However, forcing them to share has the undesirable consequence that both
xaxes must have the same labels and formatting, producing overlayed
labels that are slightly noticeable.
I have committed to SVN the change making twinx work like twiny. As an
aside, this would not be necessary if there was an easy after the fact
way of sharing and unsharing axes (i.e., ax.set_shared_x_axes(ax2)).
Cheers,
David

**********************************
David M. Kaplan
Charge de Recherche 1
Institut de Recherche pour le Developpement
Centre de Recherche Halieutique Mediterraneenne et Tropicale
av. Jean Monnet
B.P. 171
34203 Sete cedex
France
Phone: +33 (0)4 99 57 32 27
Fax: +33 (0)4 99 57 32 95
http://www.ur097.ird.fr/team/dkaplan/index.html
**********************************
