Hi all,
it seems that I am experiencing the same problem here with imshow (rather
than scatter) and AxesGrid. But calling imshow with aspect=False does not do
the trick for me.
I am trying to have two imshow subplots next to each other and a single
colorbar at the right. The data underlying the imshow's have different x-
and y-ranges but I want the x- and y-axis to have an aspect ratio of 1 (i.e.
each imshow should produce a square). I've tried aspect=False,
aspect='equal', and explicitely setting aspect=2 which should be the correct
value. See the three images below the code example.
I've also tried Grid instead of AxesGrid as suggested but I didn't manage to
achieve good results with the colorbar in that case.
I'd appreciate any help,
Matthias
Here's a more or less minimal code example:
#############################################
import numpy as np
import numpy.random as npr
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
fig = figure(1, figsize=[12,10])
grid = AxesGrid(fig, 111,
nrows_ncols = (1, 2),
axes_pad = 0.2,
share_all = False,
label_mode = 'L',
cbar_location = 'right',
cbar_mode = 'single',
cbar_pad = 0.2
)
for i in range(2):
xmin, xmax = 0., 1.
ymin, ymax = 0., 0.5
zmin, zmax = -1., 1.
# generate random data:
N = 100
X = xmin + (xmax-xmin)*npr.random((N,)) # x_i in [0, 1]
Y = ymin + (ymax-ymin)*npr.random((N,)) # y_i in [0, 0.5]
Z = zmin + (zmax-zmin)*npr.random((N,)) # z_i in [-1, 1]
# generate griddata for imshow plot:
numspaces = np.sqrt(N)
xi = linspace(xmin, xmax, numspaces)
yi = linspace(ymin, ymax, numspaces)
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='nearest')
norm = matplotlib.colors.normalize(vmin=zmin, vmax=zmax)
ax = grid[i]
im = ax.imshow(zi,
extent = [xmin,xmax,ymin,ymax],
norm = norm,
vmin = zmin,
vmax = zmax,
origin = 'lower',
aspect = 'equal', # or False, or 'auto', or 2, or ...
interpolation = 'nearest')
ax.grid(False)
ax.set_xlabel('x')
ax.set_ylabel('y')
# add a colorbar:
cbar = plt.colorbar(im, cax=grid.cbar_axes[0])
cbar.ax.set_ylabel('color level')
############################################
And here are the three resulting images:
aspect='equal':
<http://matplotlib.1069221.n5.nabble.com/file/n41075/equal.png>
aspect=False:
<http://matplotlib.1069221.n5.nabble.com/file/n41075/False.png>
aspect=2.:
<http://matplotlib.1069221.n5.nabble.com/file/n41075/two.png>
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Squashed-axes-with-AxesGrid-tp40699p41075.html
Sent from the matplotlib - users mailing list archive at Nabble.com.