8000 Add get_tightbbox to Legend · matplotlib/matplotlib@d6c5c7d · GitHub
[go: up one dir, main page]

Skip to content

Commit d6c5c7d

Browse files
committed
Add get_tightbbox to Legend
1 parent 145c3ee commit d6c5c7d

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,12 +4154,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
41544154
bbox_artists = self.get_default_bbox_extra_artists()
41554155

41564156
for a in bbox_artists:
4157-
if isinstance(a, Legend) and a.get_visible():
4158-
bb.append(a._legend_box.get_window_extent(renderer))
4159-
else:
4160-
bbox = a.get_tightbbox(renderer)
4161-
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
4162-
bb.append(bbox)
4157+
bbox = a.get_tightbbox(renderer)
4158+
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
4159+
bb.append(bbox)
41634160

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

lib/matplotlib/figure.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,13 +2241,9 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
22412241
else:
22422242
artists = bbox_extra_artists
22432243
for a in artists:
2244-
if isinstance(a, mlegend.Legend) and a.get_visible():
2245-
bb.append(a._legend_box.get_window_extent(renderer))
2246-
else:
2247-
bbox = a.get_tightbbox(renderer)
2248-
if bbox is not None and (bbox.width != 0 or
2249-
bbox.height != 0):
2250-
bb.append(bbox)
2244+
bbox = a.get_tightbbox(renderer)
2245+
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
2246+
bb.append(bbox)
22512247

22522248
for ax in self.axes:
22532249
if ax.get_visible():

lib/matplotlib/legend.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,10 @@ def get_window_extent(self, *args, **kwargs):
11251125
'Return extent of the legend.'
11261126
return self.legendPatch.get_window_extent(*args, **kwargs)
11271127

1128+
def get_tightbbox(self, renderer):
1129+
'Return extent of the legend.'
1130+
return self._legend_box.get_window_extent(renderer)
1131+
11281132
def get_frame_on(self):
11291133
"""Get whether the legend box patch is drawn."""
11301134
return self._drawFrame

0 commit comments

Comments
 (0)
0