Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5701e1

Browse files
committed
Allow SubFigure legends
1 parent 64619e5 commit b5701e1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/matplotlib/legend.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def __init__(
360360
"""
361361
# local import only to avoid circularity
362362
from matplotlib.axes import Axes
363-
from matplotlib.figure import Figure
363+
from matplotlib.figure import FigureBase
364364

365365
super().__init__()
366366

@@ -434,11 +434,13 @@ def __init__(
434434
self.isaxes = True
435435
self.axes = parent
436436
self.set_figure(parent.figure)
437-
elif isinstance(parent, Figure):
437+
elif isinstance(parent, FigureBase):
438438
self.isaxes = False
439439
self.set_figure(parent)
440440
else:
441-
raise TypeError("Legend needs either Axes or Figure as parent")
441+
raise TypeError(
442+
"Legend needs either Axes or FigureBase as parent"
443+
)
442444
self.parent = parent
443445

444446
self._loc_used_default = loc is None

0 commit comments

Comments
 (0)