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

Skip to content

Commit b90b15f

Browse files
committed
ENH: add artist.inbbox boolean
1 parent 485dd68 commit b90b15f

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
if colnum0min >= colnumCmin and colnum0min <= colnumCmax:
8164
return True
@@ -209,7 +192,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
209192
_log.debug(ax._layoutbox)
210193
if ax._layoutbox is not None:
211194
pos = ax.get_position(original=True)
212-
tightbbox = get_axall_tightbbox(ax, renderer)
195+
tightbbox = ax.get_tightbbox(renderer)
213196
bbox = invTransFig(tightbbox)
214197
# use stored h_pad if it exists
215198
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
@@ -4091,13 +4091,16 @@ def pick(self, *args):
40914091

40924092
def get_default_bbox_extra_artists(self):
40934093
return [artist for artist in self.get_children()
4094-
if artist.get_visible()]
4094+
if (artist.get_visible() and artist.inbbox)]
40954095

40964096
def get_tightbbox(self, renderer, call_axes_locator=True,
40974097
bbox_extra_artists=None):
40984098
"""
4099-
Return the tight bounding box of the axes.
4100-
The dimension of the Bbox in canvas coordinate.
4099+
Return the tight bounding box of the axes, including axis and their
4100+
decorators (xlabel, title, etc).
4101+
4102+
Artists that have ``artist.inbbox=False`` are not included
4103+
in the bbox.
41014104
41024105
Parameters
41034106
----------

lib/matplotlib/figure.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,10 +1480,7 @@ def draw(self, renderer):
14801480
try:
14811481
renderer.open_group('figure')
14821482
if self.get_constrained_layout() and self.axes:
1483-
if True:
1484-
self.execute_constrained_layout(renderer)
1485-
else:
1486-
pass
1483+
self.execute_constrained_layout(renderer)
14871484
if self.get_tight_layout() and self.axes:
14881485
try:
14891486
self.tight_layout(renderer,
@@ -2024,7 +2021,7 @@ def waitforbuttonpress(self, timeout=-1):
20242021

20252022
def get_default_bbox_extra_artists(self):
20262023
bbox_artists = [artist for artist in self.get_children()
2027-
if artist.get_visible()]
2024+
if (artist.get_visible() and artist.inbbox)]
20282025
for ax in self.axes:
20292026
if ax.get_visible():
20302027
bbox_artists.extend(ax.get_default_bbox_extra_artists())
@@ -2058,6 +2055,7 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
20582055
artists = self.get_default_bbox_extra_artists()
20592056
else:
20602057
artists = bbox_extra_artists
2058+
20612059
for a in artists:
20622060
bbox = a.get_tightbbox(renderer)
20632061
if bbox is not None and (bbox.width != 0 or bbox.height != 0):

0 commit comments

Comments
 (0)
0