matching axes lengths after calls to "set_aspect" and "colorbar"

Hi All,

I want to have two axes have the same xlimits and the same length of the x axis. However, I'd also like for the first axis to be plotted at a certain aspect ratio (its geographic if anyone is interested).

The following two tries do not work, because the "bounds" stay the same after set_aspect.

I'm sure I'm just missing some other call to the axes (or axis?) class. Is there someway at getting at the underlying length of the actual axis, not its whole bounding box?

Thanks, Jody

# this basically has no effect....
ax=subplot(2,1,1)
plot(arange(0,10),arange(0,10)*3)
ax.set_aspect(0.7)
pp = ax.get_position().bounds

axn=subplot(2,1,2)
plot(arange(0,10),rand(10))
ppn = axn.get_position().bounds
print pp
print ppn
axn.set_position([pp[0],ppn[1],pp[2],ppn[3]])
    
# Or, this zooms in on subplot 1, which is of course not what I want....

ax=subplot(2,1,1)
plot(arange(0,10),arange(0,10)*3)
ax.set_aspect(0.7)
pp = ax.get_position().bounds

axn=subplot(2,1,2,sharex=ax)
plot(arange(0,10),rand(10))
ppn = axn.get_position().bounds
print pp
print ppn
axn.set_position([pp[0],ppn[1],pp[2],ppn[3]])

···

--
Jody Klymak
http://web.uvic.ca/~jklymak/

Hi All,

I want to have two axes have the same xlimits and the same length of the x axis. However, I'd also like for the first axis to be plotted at a certain aspect ratio (its geographic if anyone is interested).

The following two tries do not work, because the "bounds" stay the same after set_aspect.

I'm sure I'm just missing some other call to the axes (or axis?) class. Is there someway at getting at the underlying length of the actual axis, not its whole bounding box?

I think there is a simpler way. Does this do what you want?

fig, axs = plt.subplots(nrows=2, sharex=True)
axs[0].set_aspect(0.7, adjustable='datalim')
axs[0].plot(np.random.rand(5))
axs[1].plot(np.random.rand(7))
plt.show()

Note that when you set the aspect, it is not applied until there is a draw() operation.

Eric

···

On 2013/03/07 12:24 PM, Jody Klymak wrote:

Thanks, Jody

# this basically has no effect....
ax=subplot(2,1,1)
plot(arange(0,10),arange(0,10)*3)
ax.set_aspect(0.7)
pp = ax.get_position().bounds

axn=subplot(2,1,2)
plot(arange(0,10),rand(10))
ppn = axn.get_position().bounds
print pp
print ppn
axn.set_position([pp[0],ppn[1],pp[2],ppn[3]])

# Or, this zooms in on subplot 1, which is of course not what I want....

ax=subplot(2,1,1)
plot(arange(0,10),arange(0,10)*3)
ax.set_aspect(0.7)
pp = ax.get_position().bounds

axn=subplot(2,1,2,sharex=ax)
plot(arange(0,10),rand(10))
ppn = axn.get_position().bounds
print pp
print ppn
axn.set_position([pp[0],ppn[1],pp[2],ppn[3]])

--
Jody Klymak
http://web.uvic.ca/~jklymak/

------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Eric,

I think there is a simpler way. Does this do what you want?

fig, axs = plt.subplots(nrows=2, sharex=True)
axs[0].set_aspect(0.7, adjustable='datalim')
axs[0].plot(np.random.rand(5))
axs[1].plot(np.random.rand(7))
plt.show()

Note that when you set the aspect, it is not applied until there is a
draw() operation.

Not quite, but the fact that I need to call get_position after a draw() call does help.

The below works, though simpler ways are very welcome. Your method zoomed out the first plot's ylimits rather than shrunk the second plot's x axis size, which isn't what I want if the first plot is geographic.

Thanks, Jody

lonz=arange(40.,42.,0.1)
latz = arange(38.,40.,0.1)
lons = arange(40.,42.,0.3)
dats = rand(shape(lons)[0])

Z = rand(shape(latz)[0],shape(lonz)[0])
ax=subplot2grid((3,1),(0,0),rowspan=2)
pcolormesh(lonz,latz,Z)
ax.set_aspect(cos(39*pi/180.))
draw()
pp=ax.get_position().bounds
xl=ax.get_xlim()

axn=subplot2grid((3,1),(2,0))
plot(lons,dats)
ppn = axn.get_position().bounds
axn.set_position([pp[0],ppn[1],pp[2],ppn[3]])
xlim(xl)

···

On Mar 7, 2013, at 14:42 PM, Eric Firing <efiring@...202...> wrote:

--
Jody Klymak
http://web.uvic.ca/~jklymak/