Possible bug / odd behaviour in GridSpec?

Hi,

I've come across something I don't entirely understand in the
behaviour of gridspec. It's not obvious from the code & docs for this
module, but is it only supposed to be able to deal with 'square'
layouts, e.g. 3x3, 4x4 etc?

Taking some code from an example on the gridspec page ...

import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
#gs = gridspec.GridSpec(3, 3) # OK
gs = gridspec.GridSpec(6, 3) # Will cause an error later on
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1,:-1])
ax3 = plt.subplot(gs[1:,-1])
ax4 = plt.subplot(gs[-1,0])
ax5 = plt.subplot(gs[-1,-2])
plt.show()

... will fail if that line is uncommented, giving an index error. I
don't see any reason why these slices should fail however, though
obviously it won't use all the available space within the whole grid?
Substituting a 'square' grid for the (6,3), e.g. (4,4), (5,5) etc
seems to be fine though.

I'm quite interested in getting involved with mpl development, partly
as a way to get my head around python & numpy and aid porting a bunch
of stuff I use over to python from IDL. Unless I'm doing something
totally wrong by expecting the above snippet to work, then I'd happily
spend some time looking into this in more detail, having written some
similar code in IDL. The docs for that module also look like they
could benefit from some work.

Cheers,

Dave

···

---------
David Andrews
PhD Student, Radio & Space Plasma Physics Group, University of Leicester, UK

2011/5/12 David Andrews <irbdavid@...287...>:

Hi,

I've come across something I don't entirely understand in the
behaviour of gridspec. It's not obvious from the code & docs for this
module, but is it only supposed to be able to deal with 'square'
layouts, e.g. 3x3, 4x4 etc?

Taking some code from an example on the gridspec page ...

import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
#gs = gridspec.GridSpec(3, 3) # OK
gs = gridspec.GridSpec(6, 3) # Will cause an error later on
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1,:-1])
ax3 = plt.subplot(gs[1:,-1])
ax4 = plt.subplot(gs[-1,0])
ax5 = plt.subplot(gs[-1,-2])
plt.show()

... will fail if that line is uncommented, giving an index error.

Works for me.
Ubuntu 11.04 Natty, stock python 2.7.1 and matplotlib 1.0.1 from
https://launchpad.net/~valavanisalex/+archive/matplotlib.

Yes, this is a bug that has been fixed.

https://github.com/matplotlib/matplotlib/commit/76851eb

Regards,

-JJ

···

On Thu, May 12, 2011 at 7:53 AM, Goyo <goyodiaz@...287...> wrote:

2011/5/12 David Andrews <irbdavid@...287...>:

Hi,

I've come across something I don't entirely understand in the
behaviour of gridspec. It's not obvious from the code & docs for this
module, but is it only supposed to be able to deal with 'square'
layouts, e.g. 3x3, 4x4 etc?

Taking some code from an example on the gridspec page ...

import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
#gs = gridspec.GridSpec(3, 3) # OK
gs = gridspec.GridSpec(6, 3) # Will cause an error later on
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1,:-1])
ax3 = plt.subplot(gs[1:,-1])
ax4 = plt.subplot(gs[-1,0])
ax5 = plt.subplot(gs[-1,-2])
plt.show()

... will fail if that line is uncommented, giving an index error.

Works for me.
Ubuntu 11.04 Natty, stock python 2.7.1 and matplotlib 1.0.1 from
https://launchpad.net/~valavanisalex/+archive/matplotlib.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Yes, the docs need lots of work I guess and any contribution will be
greatly appreciated.
If you're willing to improve the docs for gridspec, I'm more than
happy to help you (I am the main author of that module).
The best way to contribute is to use github pull request and
matplotlib is hosted here

https://github.com/matplotlib/matplotlib

Regards,

-JJ

···

On Thu, May 12, 2011 at 7:18 AM, David Andrews <irbdavid@...287...> wrote:

I'm quite interested in getting involved with mpl development, partly
as a way to get my head around python & numpy and aid porting a bunch
of stuff I use over to python from IDL. Unless I'm doing something
totally wrong by expecting the above snippet to work, then I'd happily
spend some time looking into this in more detail, having written some
similar code in IDL. The docs for that module also look like they
could benefit from some work.