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 491c388

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

File tree

Expand file treeCollapse file tree

1 file changed

+18
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-3
lines changed

‎lib/matplotlib/tight_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tight_layout.py
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,40 @@ def auto_adjust_subplotpars(
171171
margin_bottom = max([sum(s) for s in vspaces[-cols:]] + [0])
172172
margin_bottom += pad_inches / fig_height_inch
173173

174+
if margin_left + margin_right >= 1:
175+
margin_left = 0.4999
176+
margin_right = 0.4999
177+
warnings.warn('The left and right margins cannot be made large '
178+
'enough to accomodate all axes decorations. ')
174179
kwargs = dict(left=margin_left,
175180
right=1 - margin_right,
176181
bottom=margin_bottom,
177182
top=1 - margin_top)
178-
179183
if cols > 1:
180184
hspace = (
181185
max(sum(s)
182186
for i in range(rows)
183187
for s in hspaces[i * (cols + 1) + 1:(i + 1) * (cols + 1) - 1])
184188
+ hpad_inches / fig_width_inch)
189+
# axes widths:
185190
h_axes = (1 - margin_right - margin_left - hspace * (cols - 1)) / cols
186-
kwargs["wspace"] = hspace / h_axes
191+
if h_axes < 0.:
192+
warnings.warn('tight_layout cannot make axes width small enough '
193+
'to accomodate all axes decorations')
194+
kwargs["wspace"] = 0.5
195+
else:
196+
kwargs["wspace"] = hspace / h_axes
187197

188198
if rows > 1:
189199
vspace = (max(sum(s) for s in vspaces[cols:-cols])
190200
+ vpad_inches / fig_height_inch)
191201
v_axes = (1 - margin_top - margin_bottom - vspace * (rows - 1)) / rows
192-
kwargs["hspace"] = vspace / v_axes
202+
if v_axes < 0:
203+
warnings.warn('tight_layout cannot make axes height small enough '
204+
'to accomodate all axes decorations')
205+
kwargs["hspace"] = 0.5
206+
else:
207+
kwargs["hspace"] = vspace / v_axes
193208

194209
return kwargs
195210

0 commit comments

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