Skip to content

Commit c53836c

Browse files
committed
ENH have ax.get_tightbbox have a bbox around all artists
1 parent 31dab4c commit c53836c

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

2238-
bb = [artist for artist in self.get_children()
2239-
if artist.get_visible()]
2238+
bb = []
2239+
if bbox_extra_artists is None:
2240+
artists = self.get_default_bbox_extra_artists()
2241+
else:
2242+
artists = bbox_extra_artists
2243+
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_window_extent(renderer)
2248+
if a.get_clip_on():
2249+
clip_box = a.get_clip_box()
2250+
if clip_box is not None:
2251+
bbox = Bbox.intersection(bbox, clip_box)
2252+
clip_path = a.get_clip_path()
2253+
if clip_path is not None and bbox is not None:
2254+
clip_path = clip_path.get_fully_transformed_path()
2255+
bbox = Bbox.intersection(bbox,
2256+
clip_path.get_extents())
2257+
if bbox is not None and (bbox.width != 0 or
2258+
bbox.height != 0):
2259+
bb.append(bbox)
2260+
22402261
for ax in self.axes:
22412262
if ax.get_visible():
22422263
bb.append(ax.get_tightbbox(renderer, bbox_extra_artists))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy