Skip to content

[Bug]: subfigures are added in column major order #28344

@anntzer

Description

@anntzer

Bug summary

subplots() adds axes in row-major order, but subfigures() add subfigures in column-major order

Code for reproduction

from pylab import *

f = figure()
f.subplots(3, 3)
for i, ax in enumerate(f.axes): ax.set_title(i)
savefig("/tmp/subplots.png")

f = figure()
f.subfigures(3, 3)
for i, sf in enumerate(f.subfigs): sf.suptitle(i)
savefig("/tmp/subfigures.png")

Actual outcome

subplots
subplots

subfigures
subfigures

Expected outcome

Subfigures are added in row-major axis, per standard numpy defaults.

Additional information

In practice this should rarely matter, as the subfigures don't overlap so drawing order should be irrelevant... perhaps unless some artists are positioned beyond the subfigure edge and not clipped.

The behavior directly arises from the iteration in subfigures:

        sfarr = np.empty((nrows, ncols), dtype=object)
        for i in range(ncols):
            for j in range(nrows):
                sfarr[j, i] = self.add_subfigure(gs[j, i], **kwargs)

Operating system

macOS

Matplotlib Version

3.10.0.dev233+ga833d99e46

Matplotlib Backend

qtagg

Python version

3.12

Jupyter version

no

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions