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

Skip to content

Commit ee81bdf

Browse files
committed
BF: text not "draw"n shouldn't count for tightbbox
1 parent fc18ccc commit ee81bdf

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,16 @@ def test_badsubplotgrid():
288288

289289

290290
def test_collapsed():
291-
# test that if a call to tight_layout will collapses the axes that
292-
# it does not get applied:
291+
# test that if the amount of space required to make all the axes
292+
# decorations fit would mean that the actual Axes would end up with size
293+
# zero (i.e. margins add up to more than the available width) that a call
294+
# to tight_layout will not get applied:
293295
fig, ax = plt.subplots(tight_layout=True)
294296
ax.set_xlim([0, 1])
295297
ax.set_ylim([0, 1])
296298

297-
ax.annotate('BIG LONG STRING', xy=(1.25, 2), xytext=(10.5, 1.75),)
299+
ax.annotate('BIG LONG STRING', xy=(1.25, 2), xytext=(10.5, 1.75),
300+
annotation_clip=False)
298301
p1 = ax.get_position()
299302
with pytest.warns(UserWarning):
300303
plt.tight_layout()

lib/matplotlib/text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def get_window_extent(self, renderer=None, dpi=None):
874874
"""
875875
#return _unit_box
876876
if not self.get_visible():
877-
return Bbox.unit()
877+
return Bbox.null()
878878
if dpi is None:
879879
dpi = self.figure.dpi
880880
if self.get_text() == '':
@@ -1948,8 +1948,8 @@ def get_window_extent(self, renderer=None):
19481948
"""
19491949
# This block is the same as in Text.get_window_extent, but we need to
19501950
# set the renderer before calling update_positions().
1951-
if not self.get_visible():
1952-
return Bbox.unit()
1951+
if not self.get_visible() or not self._check_xy(renderer):
1952+
return Bbox.null()
19531953
if renderer is not None:
19541954
self._renderer = renderer
19551955
if self._renderer is None:

lib/matplotlib/tight_layout.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,17 @@ def auto_adjust_subplotpars(
6868

6969
if ax_bbox_list is None:
7070
ax_bbox_list = [
71-
Bbox.union([ax.get_position(original=True) for ax in subplots])
72-
for subplots in subplot_list]
71+
[ax.get_position(original=True) for ax in subplots]
72+
for subplots in subplot_list
73+
]
74+
ax_bbox_list = [
75+
Bbox.union([
76+
b for b in bbox_list
77+
if np.isfinite(b.width) and np.isfinite(b.height)
78+
and (b.width != 0 or b.height != 0)
79+
])
80+
for bbox_list in ax_bbox_list
81+
]
7382

7483
for subplots, ax_bbox, (num1, num2) in zip(subplot_list,
7584
ax_bbox_list,

0 commit comments

Comments
 (0)