Skip to content

Figure.subfigures dont show/update correctly #19947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lwelzel opened this issue Apr 12, 2021 · 4 comments · Fixed by #19949
Closed

Figure.subfigures dont show/update correctly #19947

lwelzel opened this issue Apr 12, 2021 · 4 comments · Fixed by #19949
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Milestone

Comments

@lwelzel
Copy link

lwelzel commented Apr 12, 2021

Bug report

Bug summary
When using Figure.subfigures(n, m) for any n or m larger than 2 the resulting figure does not draw properly when shown.
Instead only the subfigures at [0:2, 0] and [0:2, -1] are drawn properly.

Code for reproduction

import matplotlib.pyplot as plt

fig = plt.figure()
sub_figs = fig.subfigures(3, 3)

colors = ["red", "blue", "magenta", "gold", "green", "grey", "orange", "pink", "navy", "lightblue", "black"]

for i, (color, subfig) in enumerate(zip(colors,sub_figs.flatten())):
    subfig.set_facecolor(color)
    subfig.suptitle(f"subfig: {i}")

plt.show()

######### for (n, m) figures

import matplotlib.pyplot as plt

fig = plt.figure()
sub_figs = fig.subfigures(9, 10)

for i, subfig in enumerate(sub_figs.flatten()):
    subfig.set_facecolor("grey")
    subfig.suptitle(f"subfig: {i}")

plt.show()

Actual outcome

image

Only the subfigures at [0:2, 0] and [0:2, -1] are drawn properly for any (n, m) figure.

Expected outcome
3x3 grid with the proper face colors. Similar results for 2x3 or 3x2 or larger grids.

Matplotlib version

  • Operating system: Fedora (UNIX)
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.1
  • Matplotlib backend (print(matplotlib.get_backend())): module://backend_interagg
  • Python version: 3.7
  • Jupyter version (if applicable): NA
  • Other libraries: NA

Both python and Matplotlib from conda with manual update to Matplotlib version 3.4.1
conda channel: conda-forge

@jklymak
Copy link
Member

jklymak commented Apr 12, 2021

It works fine if you actually put something in the figures and use constrained_layout. I think what is happening is that because there is nothing in the subfigures, they are being shrunk to nothing.

import matplotlib.pyplot as plt

fig = plt.figure(constrained_layout=True)
sub_figs = fig.subfigures(3, 3)

colors = ["red", "blue", "magenta", "gold", "green", "grey", "orange", "pink", "navy", "lightblue", "black"]

for i, (color, subfig) in enumerate(zip(colors,sub_figs.flatten())):
    subfig.set_facecolor(color)
    ax = subfig.subplots()
    subfig.suptitle(f"subfig: {i}")

plt.show()

@lwelzel
Copy link
Author

lwelzel commented Apr 12, 2021

Interesting, thanks!

@jklymak
Copy link
Member

jklymak commented Apr 12, 2021

There is definitely a big bug though. Should be easy to fix, but not until 3.4.2 is released. Thanks for finding this.

@lwelzel
Copy link
Author

lwelzel commented Apr 12, 2021

Happy to help and thanks for working on matplotlib.

@jklymak jklymak added topic: geometry manager LayoutEngine, Constrained layout, Tight layout Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Apr 12, 2021
@jklymak jklymak added this to the v3.4.2 milestone Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants