Squashed axes with AxesGrid

Heya List,

See attached image for what I mean.

Here is the grid creation bit. I can't seem to figure out what might be causing such a problem.

     F = pyl.figure(1,(5.5,3.5))
     grid = AxesGrid(F, 111,
                         nrows_ncols=(1,3),
                         axes_pad = 0.1,
                         add_all=True,
                         label_mode = 'L',
                         aspect=True)

Should be simple enough right?

Screen Shot 2013-03-21 at 4.00.25 PM.png

···

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

It is not clear what your problem is.

AxesGrid implicitly assumes aspect=1 for each axes. So, I guess your y-limits are smaller (in its span) than x-limits.

If you don’t want this behavior, there is no need of using the AxesGrid. Rather use Grid, or simply subplots.

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import Grid

F = plt.figure(1,(5.5,3.5))

grid = Grid(F, 111,

nrows_ncols=(1,3),

axes_pad = 0.1,

add_all=True,

label_mode = ‘L’,

)

···

If this is not the answer you’re looking for, I recommend you to post a complete but simple script that reproduces your problem and describe the problem more explicitly.

Regards,

-JJ

On Fri, Mar 22, 2013 at 6:03 AM, Steven Boada <boada@…3847…> wrote:

Heya List,

See attached image for what I mean.

Here is the grid creation bit. I can’t seem to figure out what might be causing such a problem.

F = pyl.figure(1,(5.5,3.5))



grid = AxesGrid(F, 111,

                    nrows_ncols=(1,3),

                    axes_pad = 0.1,

                    add_all=True,

                    label_mode = 'L',

                    aspect=True)

Should be simple enough right?

Steven Boada

Doctoral Student

Dept of Physics and Astronomy

Texas A&M University

boada@…3847…


Everyone hates slow websites. So do we.

Make your web apps faster with AppDynamics

Download AppDynamics Lite for free today:

http://p.sf.net/sfu/appdyn_d2d_mar


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks JJ!

That did fix my problem, but I can't say I understand what the difference is. Why does Axesgrid make them squashed while just Grid works?

···

On Thu Mar 21 22:28:34 2013, Jae-Joon Lee wrote:

It is not clear what your problem is.
AxesGrid implicitly assumes aspect=1 for each axes. So, I guess your
y-limits are smaller (in its span) than x-limits.
If you don't want this behavior, there is no need of using the
AxesGrid. Rather use Grid, or simply subplots.

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import Grid

F = plt.figure(1,(5.5,3.5))
grid = Grid(F, 111,
            nrows_ncols=(1,3),
            axes_pad = 0.1,
            add_all=True,
            label_mode = 'L',
            )

If this is not the answer you're looking for, I recommend you to post
a complete but simple script that reproduces your problem and describe
the problem more explicitly.

Regards,

-JJ

On Fri, Mar 22, 2013 at 6:03 AM, Steven Boada <boada@…3847… > <mailto:boada@…3847…>> wrote:

    Heya List,

    See attached image for what I mean.

    Here is the grid creation bit. I can't seem to figure out what
    might be causing such a problem.

        F = pyl.figure(1,(5.5,3.5))
    grid = AxesGrid(F, 111,
                            nrows_ncols=(1,3),
                            axes_pad = 0.1,
                            add_all=True,
                            label_mode = 'L',
                            aspect=True)

    Should be simple enough right?

    --

    Steven Boada

    Doctoral Student
    Dept of Physics and Astronomy
    Texas A&M University
    boada@…3847… <mailto:boada@…3847…>

    ------------------------------------------------------------------------------
    Everyone hates slow websites. So do we.
    Make your web apps faster with AppDynamics
    Download AppDynamics Lite for free today:
    http://p.sf.net/sfu/appdyn_d2d_mar
    _______________________________________________
    Matplotlib-users mailing list
    Matplotlib-users@lists.sourceforge.net
    <mailto:Matplotlib-users@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

Well... I jumped the gun. To better illustrate the problem(s) I am having, I wrote a simple script that doesn't work...

import pylab as pyl
from mpl_toolkits.axes_grid1 import AxesGrid

# make some data
xdata = pyl.random(100) * 25.
ydata = pyl.random(100) * 8.
colordata = pyl.random(100) * 3.

# make us a figure
F = pyl.figure(1,figsize=(5.5,3.5))
grid = AxesGrid(F, 111,
         nrows_ncols=(1,2),
         axes_pad = 0.1,
         add_all=True,
         share_all = True,
         cbar_mode = 'each',
         cbar_location = 'top')

# Plot!
sc1 = grid[0].scatter(xdata, ydata, c=colordata, s=50, cmap='spectral')
sc2 = grid[1].scatter(xdata, ydata, c=colordata, s=50, cmap='spectral')

# Add colorbars
grid.cbar_axes[0].colorbar(sc1)
grid.cbar_axes[1].colorbar(sc2)

grid[0].set_xlim(0,25)
grid[0].set_ylim(0,8)

pyl.show()

And you get some squashed figures... I'll attach a png.

Thanks again.

Steven

Screen Shot 2013-03-22 at 11.27.19 AM.png

···

On Fri Mar 22 10:49:44 2013, Steven Boada wrote:

Thanks JJ!

That did fix my problem, but I can't say I understand what the
difference is. Why does Axesgrid make them squashed while just Grid
works?

On Thu Mar 21 22:28:34 2013, Jae-Joon Lee wrote:

It is not clear what your problem is.
AxesGrid implicitly assumes aspect=1 for each axes. So, I guess your
y-limits are smaller (in its span) than x-limits.
If you don't want this behavior, there is no need of using the
AxesGrid. Rather use Grid, or simply subplots.

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import Grid

F = plt.figure(1,(5.5,3.5))
grid = Grid(F, 111,
nrows_ncols=(1,3),
axes_pad = 0.1,
add_all=True,
label_mode = 'L',
)

If this is not the answer you're looking for, I recommend you to post
a complete but simple script that reproduces your problem and describe
the problem more explicitly.

Regards,

-JJ

On Fri, Mar 22, 2013 at 6:03 AM, Steven Boada <boada@…3847… >> <mailto:boada@…3847…>> wrote:

Heya List,

See attached image for what I mean.

Here is the grid creation bit. I can't seem to figure out what
might be causing such a problem.

F = pyl.figure(1,(5.5,3.5))
grid = AxesGrid(F, 111,
nrows_ncols=(1,3),
axes_pad = 0.1,
add_all=True,
label_mode = 'L',
aspect=True)

Should be simple enough right?

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@…3847… <mailto:boada@…3847…>

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
<mailto:Matplotlib-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

Steven,

Did you mean to switch back to AxesGrid? I thought you said that it was fixed with Grid.

-Sterling

···

On Mar 22, 2013, at 9:30AM, Steven Boada wrote:

Well... I jumped the gun. To better illustrate the problem(s) I am having, I wrote a simple script that doesn't work...

import pylab as pyl
from mpl_toolkits.axes_grid1 import AxesGrid

# make some data
xdata = pyl.random(100) * 25.
ydata = pyl.random(100) * 8.
colordata = pyl.random(100) * 3.

# make us a figure
F = pyl.figure(1,figsize=(5.5,3.5))
grid = AxesGrid(F, 111,
       nrows_ncols=(1,2),
       axes_pad = 0.1,
       add_all=True,
       share_all = True,
       cbar_mode = 'each',
       cbar_location = 'top')

# Plot!
sc1 = grid[0].scatter(xdata, ydata, c=colordata, s=50, cmap='spectral')
sc2 = grid[1].scatter(xdata, ydata, c=colordata, s=50, cmap='spectral')

# Add colorbars
grid.cbar_axes[0].colorbar(sc1)
grid.cbar_axes[1].colorbar(sc2)

grid[0].set_xlim(0,25)
grid[0].set_ylim(0,8)

pyl.show()

And you get some squashed figures... I'll attach a png.

Thanks again.

Steven

On Fri Mar 22 10:49:44 2013, Steven Boada wrote:

Thanks JJ!

That did fix my problem, but I can't say I understand what the
difference is. Why does Axesgrid make them squashed while just Grid
works?

On Thu Mar 21 22:28:34 2013, Jae-Joon Lee wrote:

It is not clear what your problem is.
AxesGrid implicitly assumes aspect=1 for each axes. So, I guess your
y-limits are smaller (in its span) than x-limits.
If you don't want this behavior, there is no need of using the
AxesGrid. Rather use Grid, or simply subplots.

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import Grid

F = plt.figure(1,(5.5,3.5))
grid = Grid(F, 111,
nrows_ncols=(1,3),
axes_pad = 0.1,
add_all=True,
label_mode = 'L',
)

If this is not the answer you're looking for, I recommend you to post
a complete but simple script that reproduces your problem and describe
the problem more explicitly.

Regards,

-JJ

On Fri, Mar 22, 2013 at 6:03 AM, Steven Boada <boada@…3847… >>> <mailto:boada@…3847…>> wrote:

Heya List,

See attached image for what I mean.

Here is the grid creation bit. I can't seem to figure out what
might be causing such a problem.

F = pyl.figure(1,(5.5,3.5))
grid = AxesGrid(F, 111,
nrows_ncols=(1,3),
axes_pad = 0.1,
add_all=True,
label_mode = 'L',
aspect=True)

Should be simple enough right?

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@…3847… <mailto:boada@…3847…>

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
<mailto:Matplotlib-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

<Screen Shot 2013-03-22 at 11.27.19 AM.png>------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

You used AxesGrid again, not Grid. AxesGrid implicitly applies an aspect=‘equal’ to the subplots. This means that a unit of distance on the x-axis takes the same amount of space as the same unit of distance on the y-axis. In your example, the x axis goes from 0 to 25, while the y-axis goes from 0 to 8. When aspect=‘equal’, the y-axis will then be about a third the size of the x-axis, because the y-limits are about a third the size of the x-limits.

Ben Root

···

On Fri, Mar 22, 2013 at 12:30 PM, Steven Boada <boada@…3847…> wrote:

Well… I jumped the gun. To better illustrate the problem(s) I am having, I wrote a simple script that doesn’t work…

import pylab as pyl

from mpl_toolkits.axes_grid1 import AxesGrid

make some data

xdata = pyl.random(100) * 25.

ydata = pyl.random(100) * 8.

colordata = pyl.random(100) * 3.

make us a figure

F = pyl.figure(1,figsize=(5.5,3.5))

grid = AxesGrid(F, 111,

    nrows_ncols=(1,2),

    axes_pad = 0.1,

    add_all=True,

    share_all = True,

    cbar_mode = 'each',

    cbar_location = 'top')

Plot!

sc1 = grid[0].scatter(xdata, ydata, c=colordata, s=50, cmap=‘spectral’)

sc2 = grid[1].scatter(xdata, ydata, c=colordata, s=50, cmap=‘spectral’)

Add colorbars

grid.cbar_axes[0].colorbar(sc1)

grid.cbar_axes[1].colorbar(sc2)

grid[0].set_xlim(0,25)

grid[0].set_ylim(0,8)

pyl.show()

And you get some squashed figures… I’ll attach a png.

Thanks again.

Steven

No, I am saying that your example used “AxesGrid”. Use “Grid”.

Ben Root

···

On Fri, Mar 22, 2013 at 12:39 PM, Sterling Smith <smithsp@…3304…> wrote:

Steven,

Did you mean to switch back to AxesGrid? I thought you said that it was fixed with Grid.

-Sterling

Sorry y'all. I can see the confusion.

I started with AxesGrid -- squashed.

JJ suggested Grid and that fixes the scaling problems.

I realized that using just plain Grid doesn't give me the nice controls over the colorbars (which I would like to have), so I wrote a simple script and emailed it back out. That did include AxesGrid.

According to the manual ( http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1 )...

aspect
By default (False), widths and heights of axes in the grid are scaled independently. If True, they are scaled according to their data limits (similar to aspect parameter in mpl).

Which I read as it should scale the widths and heights should not be squashed. But what Ben is telling me (thanks for the explanation) is that isn't true. Seems like there is something simple I am just missing.

Sorry for that bit of confusion.

Steven

···

On Fri Mar 22 11:39:46 2013, Benjamin Root wrote:

On Fri, Mar 22, 2013 at 12:30 PM, Steven Boada <boada@…3847… > <mailto:boada@…3847…>> wrote:

    Well... I jumped the gun. To better illustrate the problem(s) I am
    having, I wrote a simple script that doesn't work...

    import pylab as pyl
    from mpl_toolkits.axes_grid1 import AxesGrid

    # make some data
    xdata = pyl.random(100) * 25.
    ydata = pyl.random(100) * 8.
    colordata = pyl.random(100) * 3.

    # make us a figure
    F = pyl.figure(1,figsize=(5.5,3.5)__)
    grid = AxesGrid(F, 111,
            nrows_ncols=(1,2),
            axes_pad = 0.1,
            add_all=True,
            share_all = True,
            cbar_mode = 'each',
            cbar_location = 'top')

    # Plot!
    sc1 = grid[0].scatter(xdata, ydata, c=colordata, s=50,
    cmap='spectral')
    sc2 = grid[1].scatter(xdata, ydata, c=colordata, s=50,
    cmap='spectral')

    # Add colorbars
    grid.cbar_axes[0].colorbar(__sc1)
    grid.cbar_axes[1].colorbar(__sc2)

    grid[0].set_xlim(0,25)
    grid[0].set_ylim(0,8)

    pyl.show()

    And you get some squashed figures... I'll attach a png.

    Thanks again.

    Steven

You used AxesGrid again, not Grid. AxesGrid implicitly applies an
aspect='equal' to the subplots. This means that a unit of distance on
the x-axis takes the same amount of space as the same unit of distance
on the y-axis. In your example, the x axis goes from 0 to 25, while
the y-axis goes from 0 to 8. When aspect='equal', the y-axis will
then be about a third the size of the x-axis, because the y-limits are
about a third the size of the x-limits.

Ben Root

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

...and did aspect=False not give you what you want?

From what I can see http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1

contradicts itself, and the chart is correct and the description below incorrect.

FWIW, I would expect the default to be False as well, but who am I to say?

Cheers, Jody

···

On Mar 22, 2013, at 9:52 AM, Steven Boada <boada@...3847...> wrote:

Sorry y'all. I can see the confusion.

I started with AxesGrid -- squashed.

JJ suggested Grid and that fixes the scaling problems.

I realized that using just plain Grid doesn't give me the nice controls
over the colorbars (which I would like to have), so I wrote a simple
script and emailed it back out. That did include AxesGrid.

According to the manual (
http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1
)...

aspect
By default (False), widths and heights of axes in the grid are scaled
independently. If True, they are scaled according to their data limits
(similar to aspect parameter in mpl).

Which I read as it should scale the widths and heights should not be
squashed. But what Ben is telling me (thanks for the explanation) is
that isn't true. Seems like there is something simple I am just missing.

Sorry for that bit of confusion.

Steven

On Fri Mar 22 11:39:46 2013, Benjamin Root wrote:

On Fri, Mar 22, 2013 at 12:30 PM, Steven Boada <boada@…3847… >> <mailto:boada@…3847…>> wrote:

   Well... I jumped the gun. To better illustrate the problem(s) I am
   having, I wrote a simple script that doesn't work...

   import pylab as pyl
   from mpl_toolkits.axes_grid1 import AxesGrid

   # make some data
   xdata = pyl.random(100) * 25.
   ydata = pyl.random(100) * 8.
   colordata = pyl.random(100) * 3.

   # make us a figure
   F = pyl.figure(1,figsize=(5.5,3.5)__)
   grid = AxesGrid(F, 111,
           nrows_ncols=(1,2),
           axes_pad = 0.1,
           add_all=True,
           share_all = True,
           cbar_mode = 'each',
           cbar_location = 'top')

   # Plot!
   sc1 = grid[0].scatter(xdata, ydata, c=colordata, s=50,
   cmap='spectral')
   sc2 = grid[1].scatter(xdata, ydata, c=colordata, s=50,
   cmap='spectral')

   # Add colorbars
   grid.cbar_axes[0].colorbar(__sc1)
   grid.cbar_axes[1].colorbar(__sc2)

   grid[0].set_xlim(0,25)
   grid[0].set_ylim(0,8)

   pyl.show()

   And you get some squashed figures... I'll attach a png.

   Thanks again.

   Steven

You used AxesGrid again, not Grid. AxesGrid implicitly applies an
aspect='equal' to the subplots. This means that a unit of distance on
the x-axis takes the same amount of space as the same unit of distance
on the y-axis. In your example, the x axis goes from 0 to 25, while
the y-axis goes from 0 to 8. When aspect='equal', the y-axis will
then be about a third the size of the x-axis, because the y-limits are
about a third the size of the x-limits.

Ben Root

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

Hey Jody et al.

Yeah aspect = False does the trick. Thanks for the help trouble shooting.

Steven

···

On Fri Mar 22 11:59:45 2013, Jody Klymak wrote:

...and did aspect=False not give you what you want?

From what I can see http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1

contradicts itself, and the chart is correct and the description below incorrect.

FWIW, I would expect the default to be False as well, but who am I to say?

Cheers, Jody

On Mar 22, 2013, at 9:52 AM, Steven Boada <boada@...3847...> wrote:

Sorry y'all. I can see the confusion.

I started with AxesGrid -- squashed.

JJ suggested Grid and that fixes the scaling problems.

I realized that using just plain Grid doesn't give me the nice controls
over the colorbars (which I would like to have), so I wrote a simple
script and emailed it back out. That did include AxesGrid.

According to the manual (
http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axes-grid1
)...

aspect
By default (False), widths and heights of axes in the grid are scaled
independently. If True, they are scaled according to their data limits
(similar to aspect parameter in mpl).

Which I read as it should scale the widths and heights should not be
squashed. But what Ben is telling me (thanks for the explanation) is
that isn't true. Seems like there is something simple I am just missing.

Sorry for that bit of confusion.

Steven

On Fri Mar 22 11:39:46 2013, Benjamin Root wrote:

On Fri, Mar 22, 2013 at 12:30 PM, Steven Boada <boada@…3847… >>> <mailto:boada@…3847…>> wrote:

    Well... I jumped the gun. To better illustrate the problem(s) I am
    having, I wrote a simple script that doesn't work...

    import pylab as pyl
    from mpl_toolkits.axes_grid1 import AxesGrid

    # make some data
    xdata = pyl.random(100) * 25.
    ydata = pyl.random(100) * 8.
    colordata = pyl.random(100) * 3.

    # make us a figure
    F = pyl.figure(1,figsize=(5.5,3.5)__)
    grid = AxesGrid(F, 111,
            nrows_ncols=(1,2),
            axes_pad = 0.1,
            add_all=True,
            share_all = True,
            cbar_mode = 'each',
            cbar_location = 'top')

    # Plot!
    sc1 = grid[0].scatter(xdata, ydata, c=colordata, s=50,
    cmap='spectral')
    sc2 = grid[1].scatter(xdata, ydata, c=colordata, s=50,
    cmap='spectral')

    # Add colorbars
    grid.cbar_axes[0].colorbar(__sc1)
    grid.cbar_axes[1].colorbar(__sc2)

    grid[0].set_xlim(0,25)
    grid[0].set_ylim(0,8)

    pyl.show()

    And you get some squashed figures... I'll attach a png.

    Thanks again.

    Steven

You used AxesGrid again, not Grid. AxesGrid implicitly applies an
aspect='equal' to the subplots. This means that a unit of distance on
the x-axis takes the same amount of space as the same unit of distance
on the y-axis. In your example, the x axis goes from 0 to 25, while
the y-axis goes from 0 to 8. When aspect='equal', the y-axis will
then be about a third the size of the x-axis, because the y-limits are
about a third the size of the x-limits.

Ben Root

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas A&M University
boada@...3847...

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.

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
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________

Thanks for the comment, Jonathan.

Yeah, I did not expect aspect='equal' to work but I tried it anyway :wink:
Removing the extent argument indeed produces a very nice output but I have
not tried yet to also get the tick labels right. Instead, I have now
reverted back to matplotlib.pylab's subplots method and an extra axes for
the colorbar (see code below just in case somebody else can use that). With
some fiddling with spacing it looks ok now. It's just a mess to produce
differently sized figures but I probably won't need to do that.

Best, Matthias

<http://matplotlib.1069221.n5.nabble.com/file/n41080/2imshow%2B1colorbar.png>

···

###########################################################
import numpy as np
import numpy.random as npr
from scipy.interpolate import griddata
import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=[12,5])

for ax in axes:
    xmin, xmax = 0., 1.
    ymin, ymax = 0., 0.5
    zmin, zmax = -1., 1.
    
    # create 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 contour 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)
    
    im = ax.imshow(zi,
        extent = [xmin,xmax,ymin,ymax],
        norm = norm,
        vmin = zmin,
        vmax = zmax,
        origin = 'lower',
        aspect = 2.,
        interpolation = 'nearest')
    
    ax.grid(False)
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    
# add a colorbar:
fig.subplots_adjust(left=0.05, bottom=0.2, right=0.8, top=0.95, wspace=0.2,
hspace=0.2)
cbar_ax = fig.add_axes([0.85, 0.2, 0.03, 0.75])
fig.colorbar(im, cax=cbar_ax)
cbar_ax.set_ylabel('color level')
fig.subplots_adjust(left=0.05, bottom=0.2, right=0.8, top=0.95, wspace=0.2,
hspace=0.2)
##############################################################

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Squashed-axes-with-AxesGrid-tp40699p41080.html
Sent from the matplotlib - users mailing list archive at Nabble.com.