Description
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.
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
.
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