matplotlib / matplotlib/matplotlib

[Bug]: add_subfigure does not respect GridSpec parameters

Aperta
#28,132 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
23.2k
Fork
8.5k
Merge medio
1g 6h
PR unite (30g)
66

Descrizione

### 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

```Python
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](https://github.com/matplotlib/matplotlib/assets/13972103/aa289a95-97a9-428c-a3c4-30e610117858)

### 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](https://github.com/matplotlib/matplotlib/assets/13972103/dbdab0bc-1232-44f1-8877-5e4960656a07)

### 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo la riproduzione Python fornita con Matplotlib 3.8.3, quindi esamina Figure.add_subfigure e la relativa gestione di GridSpec. Confronta il risultato con Figure.add_subplot e verifica che le estensioni di GridSpec, wspace e hspace controllino il layout della subfigure come documentato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.