Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit abf260f

Browse filesBrowse files
committed
TST: tight_layout having negative width axes
1 parent 491c388 commit abf260f
Copy full SHA for abf260f

File tree

Expand file treeCollapse file tree

2 files changed

+48
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+48
-4
lines changed

‎lib/matplotlib/tests/test_tightlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_tightlayout.py
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,41 @@ def test_empty_layout():
272272

273273
fig = plt.gcf()
274274
fig.tight_layout()
275+
276+
277+
def test_verybig_decorators_horizontal():
278+
"Test that warning emitted when xlabel too big"
279+
fig, ax = plt.subplots(figsize=(3, 2))
280+
ax.set_xlabel('a' * 100)
281+
with warnings.catch_warnings(record=True) as w:
282+
fig.tight_layout()
283+
assert len(w) == 1
284+
285+
286+
def test_verybig_decorators_vertical():
287+
"Test that warning emitted when xlabel too big"
288+
fig, ax = plt.subplots(figsize=(3, 2))
289+
ax.set_ylabel('a' * 100)
290+
with warnings.catch_warnings(record=True) as w:
291+
fig.tight_layout()
292+
assert len(w) == 1
293+
294+
295+
def test_big_decorators_horizontal():
296+
"Test that warning emitted when xlabel too big"
297+
fig, axs = plt.subplots(1, 2, figsize=(3, 2))
298+
axs[0].set_xlabel('a' * 30)
299+
axs[1].set_xlabel('b' * 30)
300+
with warnings.catch_warnings(record=True) as w:
301+
fig.tight_layout()
302+
assert len(w) == 1
303+
304+
305+
def test_big_decorators_vertical():
306+
"Test that warning emitted when xlabel too big"
307+
fig, axs = plt.subplots(2, 1, figsize=(3, 2))
308+
axs[0].set_ylabel('a' * 20)
309+
axs[1].set_ylabel('b' * 20)
310+
with warnings.catch_warnings(record=True) as w:
311+
fig.tight_layout()
312+
assert len(w) == 1

‎lib/matplotlib/tight_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tight_layout.py
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ def auto_adjust_subplotpars(
175175
margin_left = 0.4999
176176
margin_right = 0.4999
177177
warnings.warn('The left and right margins cannot be made large '
178-
'enough to accomodate all axes decorations. ')
178+
'enough to accommodate all axes decorations. ')
179+
if margin_bottom + margin_top >= 1:
180+
margin_bottom = 0.4999
181+
margin_top = 0.4999
182+
warnings.warn('The bottom and top margins cannot be made large '
183+
'enough to accommodate all axes decorations. ')
184+
179185
kwargs = dict(left=margin_left,
180186
right=1 - margin_right,
181187
bottom=margin_bottom,
@@ -188,9 +194,9 @@ def auto_adjust_subplotpars(
188194
+ hpad_inches / fig_width_inch)
189195
# axes widths:
190196
h_axes = (1 - margin_right - margin_left - hspace * (cols - 1)) / cols
191-
if h_axes < 0.:
197+
if h_axes < 0:
192198
warnings.warn('tight_layout cannot make axes width small enough '
193-
'to accomodate all axes decorations')
199+
'to accommodate all axes decorations')
194200
kwargs["wspace"] = 0.5
195201
else:
196202
kwargs["wspace"] = hspace / h_axes
@@ -201,7 +207,7 @@ def auto_adjust_subplotpars(
201207
v_axes = (1 - margin_top - margin_bottom - vspace * (rows - 1)) / rows
202208
if v_axes < 0:
203209
warnings.warn('tight_layout cannot make axes height small enough '
204-
'to accomodate all axes decorations')
210+
'to accommodate all axes decorations')
205211
kwargs["hspace"] = 0.5
206212
else:
207213
kwargs["hspace"] = vspace / v_axes

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.