get nrows and ncols from Figure

Hi,

I'm using

    fig, axes = plt.subplots(nrows=2, ncols=3)

to generate a figure and later in code I would like to find out how many
columns and rows of are in the layout having only Figure object (fig).

I was not able to find those parameters stored in `fig`. I noticed that
fig.axes or fig.get_axes() return a flattened list of all axes, but
without structure (like `axes` from `plt.subplots`). What's the best
way to find out `nrows` and `ncols` from `fig`?

Thanks in advance!

Please CC me, because I'm not subscribed to the list.

Best regards,
Stefan

Wow, it is a bit convoluted. It looks like you can't get this information
directly from the figure object because it is never stored in the figure.
It is stored in the individual axes objects (go figure!). Furthermore, you
would need to watch out for the use of fig.get_axes() because other axes
may be added, such as colorbar axes and such, that were never a part of the
original set of axes.

To get the nrows/ncols from an Axes object:
nrows, ncols, _, _ = ax.get_subplotspec().get_geometry()

I hope that helps!
Ben Root

···

On Tue, Nov 3, 2015 at 5:54 AM, <aeuii at posteo.de> wrote:

Hi,

I'm using

    fig, axes = plt.subplots(nrows=2, ncols=3)

to generate a figure and later in code I would like to find out how many
columns and rows of are in the layout having only Figure object (fig).

I was not able to find those parameters stored in `fig`. I noticed that
fig.axes or fig.get_axes() return a flattened list of all axes, but
without structure (like `axes` from `plt.subplots`). What's the best
way to find out `nrows` and `ncols` from `fig`?

Thanks in advance!

Please CC me, because I'm not subscribed to the list.

Best regards,
Stefan
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151104/ebc2b406/attachment.html>