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

Skip to content

Commit d636914

Browse files
committed
FIX: Ignore spines if using tight_layout
1 parent 4bc1ca9 commit d636914

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/matplotlib/tight_layout.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def auto_adjust_subplotpars(
111111
if all(not ax.get_visible() for ax in subplots):
112112
continue
113113

114+
115+
114116
tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots
115117
if ax.get_visible()])
116118
tight_bbox = TransformedBbox(tight_bbox_raw,
@@ -176,11 +178,13 @@ def auto_adjust_subplotpars(
176178
margin_right = 0.4999
177179
warnings.warn('The left and right margins cannot be made large '
178180
'enough to accommodate all axes decorations. ')
181+
return None
179182
if margin_bottom + margin_top >= 1:
180183
margin_bottom = 0.4999
181184
margin_top = 0.4999
182185
warnings.warn('The bottom and top margins cannot be made large '
183186
'enough to accommodate all axes decorations. ')
187+
return None
184188

185189
kwargs = dict(left=margin_left,
186190
right=1 - margin_right,
@@ -302,7 +306,10 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
302306
for ax, subplotspec in zip(axes_list, subplotspec_list):
303307
if subplotspec is None:
304308
continue
305-
309+
# spines have a problem under zoom; CL ignores zoom events. TL
310+
# ignores spines...
311+
for spine in ['left', 'right', 'bottom', 'top']:
312+
ax.spines[spine].set_in_layout(False)
306313
subplots = subplot_dict.setdefault(subplotspec, [])
307314

308315
if not subplots:
@@ -354,6 +361,8 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
354361
subplot_list=subplot_list,
355362
ax_bbox_list=ax_bbox_list,
356363
pad=pad, h_pad=h_pad, w_pad=w_pad)
364+
if kwargs is None:
365+
return None
357366

358367
if rect is not None:
359368
# if rect is given, the whole subplots area (including
@@ -384,5 +393,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
384393
ax_bbox_list=ax_bbox_list,
385394
pad=pad, h_pad=h_pad, w_pad=w_pad,
386395
rect=(left, bottom, right, top))
396+
if kwargs is None:
397+
return None
387398

388399
return kwargs

0 commit comments

Comments
 (0)