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

Skip to content

Commit ec57567

Browse files
committed
ENH have ax.get_tightbbox have a bbox around all artists
1 parent 70f12ca commit ec57567

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
@@ -2211,8 +2211,29 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
22112211
`BboxBase` : containing the bounding box (in figure co-ordinates).
22122212
"""
22132213

2214-
bb = [artist for artist in self.get_children()
2215-
if artist.get_visible()]
2214+
bb = []
2215+
if bbox_extra_artists is None:
2216+
artists = self.get_default_bbox_extra_artists()
2217+
else:
2218+
artists = bbox_extra_artists
2219+
for a in artists:
2220+
if isinstance(a, mlegend.Legend) and a.get_visible():
2221+
bb.append(a._legend_box.get_window_extent(renderer))
2222+
else:
2223+
bbox = a.get_window_extent(renderer)
2224+
if a.get_clip_on():
2225+
clip_box = a.get_clip_box()
2226+
if clip_box is not None:
2227+
bbox = Bbox.intersection(bbox, clip_box)
2228+
clip_path = a.get_clip_path()
2229+
if clip_path is not None and bbox is not None:
2230+
clip_path = clip_path.get_fully_transformed_path()
2231+
bbox = Bbox.intersection(bbox,
2232+
clip_path.get_extents())
2233+
if bbox is not None and (bbox.width != 0 or
2234+
bbox.height != 0):
2235+
bb.append(bbox)
2236+
22162237
for ax in self.axes:
22172238
if ax.get_visible():
22182239
bb.append(ax.get_tightbbox(renderer, bbox_extra_artists))

0 commit comments

Comments
 (0)