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

Skip to content

Commit 70e7d18

Browse files
committed
FIX: Stop tight layout collapsing under zoom
1 parent 4bc1ca9 commit 70e7d18

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,13 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None,
23472347
from .tight_layout import (
23482348
get_renderer, get_subplotspec_list, get_tight_layout_figure)
23492349

2350+
try:
2351+
if self.canvas.toolbar._active in ('PAN', 'ZOOM'):
2352+
# don't do tight layout during zoom and pan.
2353+
return
2354+
except AttributeError:
2355+
# not toolbar, or no _active attribute..
2356+
pass
23502357
subplotspec_list = get_subplotspec_list(self.axes)
23512358
if None in subplotspec_list:
23522359
warnings.warn("This figure includes Axes that are not compatible "
@@ -2358,7 +2365,8 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None,
23582365
kwargs = get_tight_layout_figure(
23592366
self, self.axes, subplotspec_list, renderer,
23602367
pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
2361-
self.subplots_adjust(**kwargs)
2368+
if kwargs is not None:
2369+
self.subplots_adjust(**kwargs)
23622370

23632371
def align_xlabels(self, axs=None):
23642372
"""

lib/matplotlib/gridspec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def tight_layout(self, figure, renderer=None,
326326
kwargs = tight_layout.get_tight_layout_figure(
327327
figure, figure.axes, subplotspec_list, renderer,
328328
pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
329-
self.update(**kwargs)
329+
if kwargs is not None:
330+
self.update(**kwargs)
330331

331332

332333
class GridSpecFromSubplotSpec(GridSpecBase):

lib/matplotlib/tight_layout.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ def auto_adjust_subplotpars(
176176
margin_right = 0.4999
177177
warnings.warn('The left and right margins cannot be made large '
178178
'enough to accommodate all axes decorations. ')
179+
return None
179180
if margin_bottom + margin_top >= 1:
180181
margin_bottom = 0.4999
181182
margin_top = 0.4999
182183
warnings.warn('The bottom and top margins cannot be made large '
183184
'enough to accommodate all axes decorations. ')
185+
return None
184186

185187
kwargs = dict(left=margin_left,
186188
right=1 - margin_right,
@@ -354,6 +356,8 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
354356
subplot_list=subplot_list,
355357
ax_bbox_list=ax_bbox_list,
356358
pad=pad, h_pad=h_pad, w_pad=w_pad)
359+
if kwargs is None:
360+
return None
357361

358362
if rect is not None:
359363
# if rect is given, the whole subplots area (including
@@ -384,5 +388,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
384388
ax_bbox_list=ax_bbox_list,
385389
pad=pad, h_pad=h_pad, w_pad=w_pad,
386390
rect=(left, bottom, right, top))
391+
if kwargs is None:
392+
return None
387393

388394
return kwargs

0 commit comments

Comments
 (0)