E5EA Merge pull request #28629 from rcomer/axis-in_layout · matplotlib/matplotlib@121282f · GitHub
[go: up one dir, main page]

Skip to content

Commit 121282f

Browse files
authored
Merge pull request #28629 from rcomer/axis-in_layout
FIX: `Axis.set_in_layout` respected
2 parents 30f803b + a63dc33 commit 121282f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ def get_tightbbox(self, renderer=None, *, for_layout_only=False):
13621362
collapsed to near zero. This allows tight/constrained_layout to ignore
13631363
too-long labels when doing their layout.
13641364
"""
1365-
if not self.get_visible():
1365+
if not self.get_visible() or for_layout_only and not self.get_in_layout():
13661366
return
13671367
if renderer is None:
13681368
renderer = self.figure._get_renderer()

lib/matplotlib/tests/test_axis.py

Lines changed: 21 additions & 0 deletions
C542
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,24 @@ def test_tick_labelcolor_array():
88
# Smoke test that we can instantiate a Tick with labelcolor as array.
99
ax = plt.axes()
1010
XTick(ax, 0, labelcolor=np.array([1, 0, 0, 1]))
11+
12+
13+
def test_axis_not_in_layout():
14+
fig1, (ax1_left, ax1_right) = plt.subplots(ncols=2, layout='constrained')
15+
fig2, (ax2_left, ax2_right) = plt.subplots(ncols=2, layout='constrained')
16+
17+
# 100 label overlapping the end of the axis
18+
ax1_left.set_xlim([0, 100])
19+
# 100 label not overlapping the end of the axis
20+
ax2_left.set_xlim([0, 120])
21+
22+
for ax in ax1_left, ax2_left:
23+
ax.set_xticks([0, 100])
24+
ax.xaxis.set_in_layout(False)
25+
26+
for fig in fig1, fig2:
27+
fig.draw_without_rendering()
28+
29+
# Positions should not be affected by overlapping 100 label
30+
assert ax1_left.get_position().bounds == ax2_left.get_position().bounds
31+
assert ax1_right.get_position().bounds == ax2_right.get_position().bounds

0 commit comments

Comments
 (0)
0