matplotlib / matplotlib/matplotlib

[Bug]: add_subfigure does not respect GridSpec parameters

Offen
#28,132 4 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
23.2k
Forks
8.5k
Ø Merge
1 T. 6 Std.
Gemergte PRs (30 T.)
66

Beschreibung

Bug summary

According the documentation for Figure.add_subfigure, you should be able to use GridSpec to create a set of subfigures to fill a certain space of a parent figure. However, no matter what settings are input into GridSpec, the parent figure is divided into equally sized subfigures. Doing this same process with Figure.add_subplot produces the expected results with the axes bounded by the input extent and separated by the correct hspace and wspace.

Code for reproduction
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import numpy as np

dpi = 100
width = 600
height = 600

main = plt.figure(figsize=(width / dpi, height / dpi), dpi=100,
                  facecolor='#9a9a9a', frameon=False)

gs = GridSpec(2, 4, left=.1, right=.9, bottom=0.1,
              top=0.9, wspace=0.15, hspace=0.15)

colors = np.array([
    ['red', 'black', 'green', 'blue'],
    ['brown', 'gray', 'white', 'gold']
])

panels = []
for row in range(2):
    for col in range(4):
        main.add_subfigure(gs[row, col], facecolor=colors[row][col])

plt.show()
Actual outcome

The output is equally sized subfigures without any space between them and the full extent being used despite the input restrictions.
test_add_subfig

Expected outcome

What is expected is a properly spaced areas with the proper extent. This can be produced when using add_subplot instead of add_subfigure.
test_add_subplot

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.3

Matplotlib Backend

No response

Python version

3.12.2

Jupyter version

No response

Installation

conda

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie zunächst die bereitgestellte Python-Reproduktion mit Matplotlib 3.8.3 aus und untersuchen Sie anschließend Figure.add_subfigure und dessen GridSpec-Behandlung. Vergleichen Sie das Ergebnis mit Figure.add_subplot und überprüfen Sie, dass GridSpec-Ausdehnungen, wspace und hspace das Subfigure-Layout wie dokumentiert steuern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.