Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
The overloads forsubfigures
aren't quite correct
The issue is that
matplotlib/lib/matplotlib/figure.py
Line 1604 in4af03f4
defsubfigures(self,nrows=1,ncols=1,squeeze=True, |
hassqueeze=True
as the default, but the first overload incorrectly notesFalse
as the default
matplotlib/lib/matplotlib/figure.pyi
Lines 193 to 204 in1295158
@overload | |
defsubfigures( | |
self, | |
nrows:int= ..., | |
ncols:int= ..., | |
squeeze:Literal[False]= ..., | |
wspace:float|None= ..., | |
hspace:float|None= ..., | |
width_ratios:ArrayLike|None= ..., | |
height_ratios:ArrayLike|None= ..., | |
**kwargs | |
)->np.ndarray: ... |
Code for reproduction
importmatplotlib.pyplotaspltfromtypingimportreveal_typefig=plt.figure(layout='constrained',figsize=(10,4))reveal_type(fig.subfigures(1,2,wspace=0.07))reveal_type(fig.subfigures(1,1,wspace=0.07))reveal_type(fig.subfigures(1,2,wspace=0.07,squeeze=True))reveal_type(fig.subfigures(1,1,wspace=0.07,squeeze=True))
Actual outcome
(running the above with mypy)
t.py:6: note: Revealed type is "numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]]"t.py:7: note: Revealed type is "numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]]"t.py:9: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:10: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"
Note that the reveal types differ, even thoughsqueeze=True
is the default
Expected outcome
t.py:6: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:7: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:9: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:10: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"
Additional information
No response
Operating system
No response
Matplotlib Version
3.10.3
Matplotlib Backend
No response
Python version
3.12
Jupyter version
No response
Installation
pip