Skip to content

Commit 28b6977

Browse files
committed
include overspilling axes legends in ax.get_tightbbox
1 parent d02024e commit 28b6977

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/matplotlib/axes/_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import matplotlib.image as mimage
3434
from matplotlib.offsetbox import OffsetBox
3535
from matplotlib.artist import allow_rasterization
36+
from matplotlib.legend import Legend
3637

3738
from matplotlib.rcsetup import cycler
3839
from matplotlib.rcsetup import validate_axisbelow
@@ -3941,6 +3942,8 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
39413942
for child in self.get_children():
39423943
if isinstance(child, OffsetBox) and child.get_visible():
39433944
bb.append(child.get_window_extent(renderer))
3945+
elif isinstance(child, Legend) and child.get_visible():
3946+
bb.append(child._legend_box.get_window_extent(renderer))
39443947

39453948
_bbox = mtransforms.Bbox.union(
39463949
[b for b in bb if b.width != 0 or b.height != 0])

0 commit comments

Comments
 (0)