8000 Merge pull request #20091 from anntzer/tl · matplotlib/matplotlib@a94acb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit a94acb3

Browse files
authored
Merge pull request #20091 from anntzer/tl
Cleanup tight_layout.
2 parents 37fcc3f + 5062c62 commit a94acb3

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``tight_layout.auto_adjust_subplotpars``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated.

lib/matplotlib/tight_layout.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
import numpy as np
1313

14-
from matplotlib import _api, rcParams
14+
from matplotlib import _api, docstring, rcParams
1515
from matplotlib.font_manager import FontProperties
1616
from matplotlib.transforms import TransformedBbox, Bbox
1717

1818

19-
def auto_adjust_subplotpars(
19+
def _auto_adjust_subplotpars(
2020
fig, renderer, nrows_ncols, num1num2_list, subplot_list,
2121
ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
2222
"""
@@ -90,8 +90,6 @@ def auto_adjust_subplotpars(
9090
fig.transFigure.inverted())
9191

9292
row1, col1 = divmod(num1, cols)
93-
if num2 is None:
94-
num2 = num1
9593
row2, col2 = divmod(num2, cols)
9694

9795
for row_i in range(row1, row2 + 1):
@@ -174,6 +172,18 @@ def auto_adjust_subplotpars(
174172
return kwargs
175173

176174

175+
@_api.deprecated("3.5")
1 10000 76+
@docstring.copy(_auto_adjust_subplotpars)
177+
def auto_adjust_subplotpars(
178+
fig, renderer, nrows_ncols, num1num2_list, subplot_list,
179+
ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
180+
num1num2_list = [
181+
(n1, n1 if n2 is None else n2) for n1, n2 in num1num2_list]
182+
return _auto_adjust_subplotpars(
183+
fig, renderer, nrows_ncols, num1num2_list, subplot_list,
184+
ax_bbox_list, pad, h_pad, w_pad, rect)
185+
186+
177187
def get_renderer(fig):
178188
if fig._cachedRenderer:
179189
return fig._cachedRenderer
@@ -298,23 +308,19 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
298308
'multiples of one another.')
299309
return {}
300310

301-
rowNum1, colNum1 = divmod(num1, cols)
302-
if num2 is None:
303-
rowNum2, colNum2 = rowNum1, colNum1
304-
else:
305-
rowNum2, colNum2 = divmod(num2, cols)
311+
row1, col1 = divmod(num1, cols)
312+
row2, col2 = divmod(num2, cols)
306313

307-
num1num2_list.append((rowNum1 * div_row * max_ncols +
308-
colNum1 * div_col,
309-
((rowNum2 + 1) * div_row - 1) * max_ncols +
310-
(colNum2 + 1) * div_col - 1))
314+
num1num2_list.append((row1 * div_row * max_ncols + col1 * div_col,
315+
((row2 + 1) * div_row - 1) * max_ncols +
316+
(col2 + 1) * div_col - 1))
311317

312-
kwargs = auto_adjust_subplotpars(fig, renderer,
313-
nrows_ncols=(max_nrows, max_ncols),
314-
num1num2_list=num1num2_list,
315-
subplot_list=subplot_list,
316-
ax_bbox_list=ax_bbox_list,
317-
pad=pad, h_pad=h_pad, w_pad=w_pad)
318+
kwargs = _auto_adjust_subplotpars(fig, renderer,
319+
nrows_ncols=(max_nrows, max_ncols),
320+
num1num2_list=num1num2_list,
321+
subplot_list=subplot_list,
322+
ax_bbox_list=ax_bbox_list,
323+
pad=pad, h_pad=h_pad, w_pad=w_pad)
318324

319325
# kwargs can be none if tight_layout fails...
320326
if rect is not None and kwargs is not None:
@@ -336,12 +342,12 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
336342
if top is not None:
337343
top -= (1 - kwargs["top"])
338344

339-
kwargs = auto_adjust_subplotpars(fig, renderer,
340-
nrows_ncols=(max_nrows, max_ncols),
341-
num1num2_list=num1num2_list,
342-
subplot_list=subplot_list,
343-
ax_bbox_list=ax_bbox_list,
344-
pad=pad, h_pad=h_pad, w_pad=w_pad,
345-
rect=(left, bottom, right, top))
345+
kwargs = _auto_adjust_subplotpars(fig, renderer,
346+
nrows_ncols=(max_nrows, max_ncols),
347+
num1num2_list=num1num2_list,
348+
subplot_list=subplot_list,
349+
ax_bbox_list=ax_bbox_list,
350+
pad=pad, h_pad=h_pad, w_pad=w_pad,
351+
rect=(left, bottom, right, top))
346352

347353
return kwargs

0 commit comments

Comments
 (0)
0