@@ -2094,15 +2094,26 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
20942094 renderer = self .figure ._cachedRenderer
20952095 bbox_inches = self .figure .get_tightbbox (renderer )
20962096
2097- bbox_extra_artists = kwargs .pop ("bbox_extra_artists" , None )
2098- if bbox_extra_artists is None :
2099- bbox_extra_artists = self .figure .get_default_bbox_extra_artists ()
2097+ bbox_artists = kwargs .pop ("bbox_extra_artists" , None )
2098+ if bbox_artists is None :
2099+ bbox_artists = self .figure .get_default_bbox_extra_artists ()
2100+
2101+ bbox_filtered = []
2102+ for a in bbox_artists :
2103+ bbox = a .get_window_extent (renderer )
2104+ if a .get_clip_on ():
2105+ clip_box = a .get_clip_box ()
2106+ if clip_box is not None :
2107+ bbox = Bbox .intersection (bbox , clip_box )
2108+ clip_path = a .get_clip_path ()
2109+ if clip_path is not None and bbox is not None :
2110+ clip_path = clip_path .get_fully_transformed_path ()
2111+ bbox = Bbox .intersection (bbox ,
2112+ clip_path .get_extents ())
2113+ if bbox is not None and (bbox .width != 0 or
2114+ bbox .height != 0 ):
2115+ bbox_filtered .append (bbox )
21002116
2101- bb = [a .get_window_extent (renderer )
2102- for a in bbox_extra_artists ]
2103-
2104- bbox_filtered = [b for b in bb
2105- if b .width != 0 or b .height != 0 ]
21062117 if bbox_filtered :
21072118 _bbox = Bbox .union (bbox_filtered )
21082119 trans = Affine2D ().scale (1.0 / self .figure .dpi )
0 commit comments