Matthias,
It's clear to me why apect='equal' doesn't work for you. That option
means to give the axes equal scaling -- i.e., the ratio of length in
axis units to length in the plot is the same for both axes, so that an
axis that goes from 0 to 1 will be twice as long as one that goes from 0
to 0.5. What is quite unclear to me is why aspect=2 should give a
result like it does. You can get the right image, though wrong tick
labeling, if you omit the extent argument to imshow.
Jon
On Thu, 2013-05-16 at 12:43 -0700, Matthias Flor wrote:
> 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.
>
>
--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
[email protected] 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users