set_aspect with shared axes

Hi,

Does anyone know why set_aspect('equal', 'box') isn't accepted on shared axes?
I'm trying to make the following type of scenario work:

import numpy as np
from matplotlib.pyplot import figure, show

fig1 = figure()
fig2 = figure()

ax1 = fig1.add_subplot(1, 1, 1)
ax1.set_aspect('equal', 'datalim')

ax2 = fig2.add_subplot(1, 2, 1, sharex=ax1, sharey=ax1)
ax2.set_aspect('equal', 'datalim')
ax3 = fig2.add_subplot(1, 2, 2, sharex=ax2, sharey=ax2)

data = np.random.rand(50,50)
ax1.pcolormesh(data)
ax2.pcolormesh(data)
ax3.pcolormesh(data)

show()

Basically, I have multiple figures with multiple subplots, all of which should be
displaying the same range. However, the different figures have different numbers
of subplots. The example above doesn't work, because once you zoom into one of
the figures, it iteratively zooms out, adjusting data limits until both figures
have their aspect ratio properly set again. I thought using 'box' might
alleviate the problem, but that's throwing an exception.

I realize making the figures have the same layout would solve the problem, I just
wasn't sure if there was another way.

Ryan

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Ryan May wrote:

Hi,

Does anyone know why set_aspect('equal', 'box') isn't accepted on shared axes?
I'm trying to make the following type of scenario work:

Ryan,

Mark Bakker keeps asking about this, too.

I have never been able to figure out an algorithm, consistent with the present mpl architecture, that would cleanly handle shared axes with fixed aspect ratio when the box is adjustable. If you can specify exactly what should happen under all such conditions that might arise--including single or dual shared axes, and fixed aspect ratio on one or more of the plots with shared axes, and any kind of zooming or panning--then we should be able to come up with the logic to implement it.

Maybe the problem is not that there is no such specification or algorithm, but that it requires a global solution, involving figuring out the dimensions of all the boxes at the same time, whereas with adjustable datalim the calculation can be done on any subplot individually--hence it can be in Axes.draw, as at present. I suspect this is the crux of it--fixed aspect ratio, shared axes, adjustable box would require a level of code that does not exist at present; a method invoked at the Figure.draw() level that would calculate and freeze all of the axes positions in one whack before any of them are drawn.

Actually, even this is not right, because IIRC axes can be shared across figures, so this calculation would need to be done at the highest level--before the Figure.draw() method.

If we go this route--which sounds like going to full-fledged sizer/pack type algorithms--we need to be sure it does not slow down interactive responsiveness. Or burden us with bugs and unmaintainable code. Sometimes it is worthwhile to accept some limitations and keep things simple.

Note that the present implementation of shared axes, unlike an earlier implementation, has no notion of master and slaves; all are equivalent, and can be calculated and drawn in any order.

Eric

···

import numpy as np
from matplotlib.pyplot import figure, show

fig1 = figure()
fig2 = figure()

ax1 = fig1.add_subplot(1, 1, 1)
ax1.set_aspect('equal', 'datalim')

ax2 = fig2.add_subplot(1, 2, 1, sharex=ax1, sharey=ax1)
ax2.set_aspect('equal', 'datalim')
ax3 = fig2.add_subplot(1, 2, 2, sharex=ax2, sharey=ax2)

data = np.random.rand(50,50)
ax1.pcolormesh(data)
ax2.pcolormesh(data)
ax3.pcolormesh(data)

show()

Basically, I have multiple figures with multiple subplots, all of which should be
displaying the same range. However, the different figures have different numbers
of subplots. The example above doesn't work, because once you zoom into one of
the figures, it iteratively zooms out, adjusting data limits until both figures
have their aspect ratio properly set again. I thought using 'box' might
alleviate the problem, but that's throwing an exception.

I realize making the figures have the same layout would solve the problem, I just
wasn't sure if there was another way.

Ryan