8000 ENH have ax.get_tightbbox have a bbox around all artists · matplotlib/matplotlib@7a33f0a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a33f0a

Browse files
committed
ENH have ax.get_tightbbox have a bbox around all artists
1 parent 687155a commit 7a33f0a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,8 +2052,29 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
20522052
`BboxBase` : containing the bounding box (in figure co-ordinates).
20532053
"""
20542054

2055-
bb = [artist for artist in self.get_children()
2056-
if artist.get_visible()]
2055+
bb = []
2056+
if bbox_extra_artists is None:
2057+
artists = self.get_default_bbox_extra_artists()
2058+
else:
2059+
artists = bbox_extra_artists
2060+
for a in artists:
2061+
if isinstance(a, mlegend.Legend) and a.get_visible():
2062+
bb.append(a._legend_box.get_window_extent(renderer))
2063+
else:
2064+
bbox = a.get_window_extent(renderer)
2065+
if a.get_clip_on():
2066+
clip_box = a.get_clip_box()
2067+
if clip_box is not None:
2068+
bbox = Bbox.intersection(bbox, clip_box)
2069+
clip_path = a.get_clip_path()
2070+
if clip_path is not None and bbox is not None:
2071+
clip_path = clip_path.get_fully_transformed_path()
2072+
bbox = Bbox.intersection(bbox,
2073+
clip_path.get_extents())
2074+
if bbox is not None and (bbox.width != 0 or
2075+
bbox.height != 0):
2076+
bb.append(bbox)
2077+
20572078
for ax in self.axes:
20582079
if ax.get_visible():
20592080
bb.append(ax.get_tightbbox(renderer, bbox_extra_artists))

0 commit comments

Comments
 (0)
0