Combining figures

Hi John, Thanks for taking the time to answer a badly

    > formulated question. With your indications, I have been
    > able to get an example working.

Great.

    > s1.set_xlim(s2.get_xlim())

There is a nice little trick where you can make two axes share the
same xaxis. Then when you pan or zoom on one, the other is
automagically changed to

ax1 = subplot(211)
ax2 = subplot(212, sharex=ax1)

Ditto for sharey. A very useful trick!

JDH

There is a nice little trick where you can make two axes share the

same xaxis. Then when you pan or zoom on one, the other is
automagically changed to

ax1 = subplot(211)
ax2 = subplot(212, sharex=ax1)

But that’s not retroactive, or is it ? i.e. if ax2 has a wider x range than ax1, it won’t show up.

f = figure(1)
s1 = subplot(211)
s1.plot([1,2,3], [1,2,3])
s2 = subplot(212, sharex = s1)
s2.plot([4,5,6], [1,2,3])

I came up with the following function to solve that problem. Is there a more elegant solution?

def uniform_limits(axes, xrange = ‘widest’, yrange = ‘widest’):

"""For all axes, sets xlim and ylim to the widest (shortest) range."""

x = []

y = []

for ax in axes:

    x.append(ax.get_xlim())

    y.append(ax.get_ylim())

x = vstack(asarray(x))

y = vstack(asarray(y))

if xrange == 'widest':

    xlims = x.min(0)[0], x.max(0)[1]       

elif xrange == 'shortest':

    xlims = x.max(0)[0], x.min(0)[1]

if yrange == 'widest':

    ylims = y.min(0)[0], y.max(0)[1]

elif yrange == 'shortest':

    ylims = y.max(0)[0], y.min(0)[1]

setp(axes, 'xlim', xlims, 'ylim', ylims)   

David