matplotlib / matplotlib/matplotlib

[Bug]: add_subfigure does not respect GridSpec parameters

オープン
#28,132 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
23.2k
フォーク
8.5k
平均マージ
1日 6時間
マージ済み PR(30日)
66

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されている Python の再現コードを Matplotlib 3.8.3 で実行し、次に Figure.add_subfigure とその GridSpec の処理を調べます。結果を Figure.add_subplot と比較し、GridSpec の範囲、wspace、hspace がドキュメントどおりにサブフィギュアのレイアウトを制御することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。