8000 ENH: add artist.inbbox boolean · matplotlib/matplotlib@d948583 · GitHub
[go: up one dir, main page]

Skip to content

Commit d948583

Browse files
committed
ENH: add artist.inbbox boolean
1 parent 55c81e4 commit d948583

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,6 @@
5959
_log = logging.getLogger(__name__)
6060

6161

62-
def get_axall_tightbbox(ax, renderer):
63-
'''
64-
Get the tight_bbox of the axis ax, and any dependent decorations, like
65-
a `Legend` instance.
66-
'''
67-
68-
# main bbox of the axis....
69-
bbox = ax.get_tightbbox(renderer=renderer)
70-
# now add the possibility of the legend...
71-
for child in ax.get_children():
72-
if isinstance(child, Legend):
73-
bboxn = child._legend_box.get_window_extent(renderer)
74-
bbox = transforms.Bbox.union([bbox, bboxn])
75-
# add other children here....
76-
return bbox
77-
78-
7962
def in_same_column(colnum0min, colnum0max, colnumCmin, colnumCmax):
8063
return (colnumCmin <= colnum0min <= colnumCmax
8164
or colnumCmin <= colnum0max <= colnumCmax)
@@ -203,7 +186,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
203186
_log.debug(ax._layoutbox)
204187
if ax._layoutbox is not None:
205188
pos = ax.get_position(original=True)
206-
tightbbox = get_axall_tightbbox(ax, renderer)
189+
tightbbox = ax.get_tightbbox(renderer)
207190
bbox = invTransFig(tightbbox)
208191
# use stored h_pad if it exists
209192
h_padt = ax._poslayoutbox.h_pad

lib/matplotlib/artist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def __init__(self):
119119
self._sketch = rcParams['path.sketch']
120120
self._path_effects = rcParams['path.effects']
121121
self._sticky_edges = _XYPair([], [])
122+
self.inbbox = True
122123

123124
def __getstate__(self):
124125
d = self.__dict__.copy()
@@ -280,8 +281,7 @@ def get_tightbbox(self, renderer):
280281
clip_path = self.get_clip_path()
281282
if clip_path is not None and bbox is not None:
282283
clip_path = clip_path.get_fully_transformed_path()
283-
bbox = Bbox.intersection(bbox,
284-
clip_path.get_extents())
284+
bbox = Bbox.intersection(bbox, clip_path.get_extents())
285285
return bbox
286286

287287
def add_callback(self, func):

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,13 +4097,16 @@ def pick(self, *args):
40974097

40984098
def get_default_bbox_extra_artists(self):
40994099
return [artist for artist in self.get_children()
4100-
if artist.get_visible()]
4100+
if (artist.get_visible() and artist.inbbox)]
41014101

41024102
def get_tightbbox(self, renderer, call_axes_locator=True,
41034103
bbox_extra_artists=None):
41044104
"""
4105-
Return the tight bounding box of the axes.
4106-
The dimension of the Bbox in canvas coordinate.
4105+
Return the tight bounding box of the axes, including axis and their
4106+
decorators (xlabel, title, etc).
4107+
4108+
Artists that have ``artist.inbbox=False`` are not included
4109+
in the bbox.
41074110
41084111
Parameters
41094112
----------

lib/matplotlib/figure.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,7 @@ def draw(self, renderer):
14501450
try:
14511451
renderer.open_group('figure')
14521452
if self.get_constrained_layout() and self.axes:
1453-
if True:
1454-
self.execute_constrained_layout(renderer)
1455-
else:
1456-
pass
1453+
self.execute_constrained_layout(renderer)
14571454
if self.get_tight_layout() and self.axes:
14581455
try:
14591456
self.tight_layout(renderer,
@@ -1993,7 +1990,7 @@ def waitforbuttonpress(self, timeout=-1):
19931990

19941991
def get_default_bbox_extra_artists(self):
19951992
bbox_artists = [artist for artist in self.get_children()
1996-
if artist.get_visible()]
1993+
if (artist.get_visible() and artist.inbbox)]
19971994
for ax in self.axes:
19981995
if ax.get_visible():
19991996
bbox_artists.extend(ax.get_default_bbox_extra_artists())
@@ -2027,6 +2024,7 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
20272024
artists = self.get_default_bbox_extra_artists()
20282025
else:
20292026
artists = bbox_extra_artists
2027+
20302028
for a in artists:
20312029
bbox = a.get_tightbbox(renderer)
20322030
if bbox is not None and (bbox.width != 0 or bbox.height != 0):

0 commit comments

Comments
 (0)
0