GridSpec Index Order

Hello,

I just noticed that in order to get a 3 row by 4 column grid, I have to
do

    import matplotlib.pyplot as plt
    from matplotlib.gridspec import GridSpec
    
    def make_ticklabels_invisible(fig):
        for i, ax in enumerate(fig.axes):
            ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
            for tl in ax.get_xticklabels() + ax.get_yticklabels():
                tl.set_visible(False)
    
    plt.figure()
    
    gs = GridSpec(3, 4)
    
    for i in range(4):
        for j in range(3):
            plt.subplot(gs[i, j])
            
    plt.suptitle("GridSpec")
    make_ticklabels_invisible(plt.gcf())
    plt.show()
    
So I have to instantiate GridSpec with a (rows, column), but when I
index the grid I have to use (column, row).

Is there any reason for this counterintuitive behaviour?

Best,

   -Nikolaus

···

--
»Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C

This is not an intended behavior but a bug which affects a grid of
non-square shape.
This has been fixed in the svn version.

Meanwhile, you may use 1-d indexing. e.g.,

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

gs = GridSpec(3, 4)

for irow in range(3):
    for icol in range(4):
        ax = plt.subplot(gs[irow*4+icol])

Regards,

-JJ

···

On Mon, Oct 25, 2010 at 10:45 PM, Nikolaus Rath <Nikolaus@...3072...> wrote:

So I have to instantiate GridSpec with a (rows, column), but when I
index the grid I have to use (column, row).

Is there any reason for this counterintuitive behaviour?

I see, thanks. Is there also a way to use this workaround for slices? I
want a subplot in column 4 that spans all rows...

Best,

   -Nikolaus

···

On 10/25/2010 11:18 AM, Jae-Joon Lee wrote:

On Mon, Oct 25, 2010 at 10:45 PM, Nikolaus Rath <Nikolaus@...3072...> wrote:

So I have to instantiate GridSpec with a (rows, column), but when I
index the grid I have to use (column, row).

Is there any reason for this counterintuitive behaviour?

This is not an intended behavior but a bug which affects a grid of
non-square shape.
This has been fixed in the svn version.

Meanwhile, you may use 1-d indexing. e.g.,

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

gs = GridSpec(3, 4)

for irow in range(3):
    for icol in range(4):
        ax = plt.subplot(gs[irow*4+icol])

--
»Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C

Try this.

def get_indx(irow, icol):
    return irow*4+icol

ax = plt.subplot(gs[get_indx(0,3):get_indx(3,3)])

With 1d slicing, the axes will occupy the rectangle defined by the
start and stop location.
For example,

gs[i:j]

will occupy the rectangular area between

gs[i] and gs[j-1].

Let me know if this does not work (this is only tested w/ the svn
version and may not work with v1.0).

Regards,

-JJ

···

On Tue, Oct 26, 2010 at 12:30 AM, Nikolaus Rath <Nikolaus@...3072...> wrote:

On 10/25/2010 11:18 AM, Jae-Joon Lee wrote:

On Mon, Oct 25, 2010 at 10:45 PM, Nikolaus Rath <Nikolaus@...3072...> wrote:

So I have to instantiate GridSpec with a (rows, column), but when I
index the grid I have to use (column, row).

Is there any reason for this counterintuitive behaviour?

This is not an intended behavior but a bug which affects a grid of
non-square shape.
This has been fixed in the svn version.

Meanwhile, you may use 1-d indexing. e.g.,

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

gs = GridSpec(3, 4)

for irow in range(3):
for icol in range(4):
ax = plt.subplot(gs[irow*4+icol])

I see, thanks. Is there also a way to use this workaround for slices? I
want a subplot in column 4 that spans all rows...

Best,

-Nikolaus

--
»Time flies like an arrow, fruit flies like a Banana.«

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C