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

Skip to content

Commit 83858f4

Browse files
authored
Merge pull request #25785 from QuLogic/ps-papersize-auto
Deprecate papersize=auto in PostScript
2 parents c5cab93 + 0615b80 commit 83858f4

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Automatic papersize selection in PostScript
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Setting :rc:`ps.papersize` to ``'auto'`` or passing ``papersize='auto'`` to
5+
`.Figure.savefig` is deprecated. Either pass an explicit paper type name, or
6+
omit this parameter to use the default from the rcParam.

lib/matplotlib/backends/backend_ps.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -872,18 +872,24 @@ def _print_figure(
872872
# find the appropriate papertype
873873
width, height = self.figure.get_size_inches()
874874
if papertype == 'auto':
875-
papertype = _get_papertype(
876-
*orientation.swap_if_landscape((width, height)))
877-
paper_width, paper_height = orientation.swap_if_landscape(
878-
papersize[papertype])
875+
_api.warn_deprecated("3.8", name="papertype='auto'",
876+
addendum="Pass an explicit paper type, or omit the "
877+
"*papertype* argument entirely.")
878+
papertype = _get_papertype(*orientation.swap_if_landscape((width, height)))
879879

880-
if mpl.rcParams['ps.usedistiller']:
881-
# distillers improperly clip eps files if pagesize is too small
882-
if width > paper_width or height > paper_height:
883-
papertype = _get_papertype(
884-
*orientation.swap_if_landscape((width, height)))
885-
paper_width, paper_height = orientation.swap_if_landscape(
886-
papersize[papertype])
880+
if is_eps:
881+
paper_width, paper_height = width, height
882+
else:
883+
paper_width, paper_height = orientation.swap_if_landscape(
884+
papersize[papertype])
885+
886+
if mpl.rcParams['ps.usedistiller']:
887+
# distillers improperly clip eps files if pagesize is too small
888+
if width > paper_width or height > paper_height:
889+
papertype = _get_papertype(
890+
*orientation.swap_if_landscape((width, height)))
891+
paper_width, paper_height = orientation.swap_if_landscape(
892+
papersize[papertype])
887893

888894
# center the figure on the paper
889895
xo = 72 * 0.5 * (paper_width - width)
@@ -1060,6 +1066,9 @@ def _print_figure_tex(
10601066
self.figure.get_size_inches())
10611067
else:
10621068
if papertype == 'auto':
1069+
_api.warn_deprecated("3.8", name="papertype='auto'",
1070+
addendum="Pass an explicit paper type, or "
1071+
"omit the *papertype* argument entirely.")
10631072
papertype = _get_papertype(width, height)
10641073
paper_width, paper_height = papersize[papertype]
10651074

lib/matplotlib/rcsetup.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,19 @@ def validate_ps_distiller(s):
438438
return ValidateInStrings('ps.usedistiller', ['ghostscript', 'xpdf'])(s)
439439

440440

441+
def _validate_papersize(s):
442+
# Re-inline this validator when the 'auto' deprecation expires.
443+
s = ValidateInStrings("ps.papersize",
444+
["auto", "letter", "legal", "ledger",
445+
*[f"{ab}{i}" for ab in "ab" for i in range(11)]],
446+
ignorecase=True)(s)
447+
if s == "auto":
448+
_api.warn_deprecated("3.8", name="ps.papersize='auto'",
449+
addendum="Pass an explicit paper type, or omit the "
450+
"*ps.papersize* rcParam entirely.")
451+
return s
452+
453+
441454
# A validator dedicated to the named line styles, based on the items in
442455
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
443456
_validate_named_linestyle = ValidateInStrings(
@@ -1247,9 +1260,7 @@ def _convert_validator_spec(key, conv):
12471260
"tk.window_focus": validate_bool, # Maintain shell focus for TkAgg
12481261

12491262
# Set the papersize/type
1250-
"ps.papersize": _ignorecase(["auto", "letter", "legal", "ledger",
1251-
*[f"{ab}{i}"
1252-
for ab in "ab" for i in range(11)]]),
1263+
"ps.papersize": _validate_papersize,
12531264
"ps.useafm": validate_bool,
12541265
# use ghostscript or xpdf to distill ps output
12551266
"ps.usedistiller": validate_ps_distiller,

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,12 @@ def test_colorbar_shift(tmp_path):
336336
norm = mcolors.BoundaryNorm([-1, -0.5, 0.5, 1], cmap.N)
337337
plt.scatter([0, 1], [1, 1], c=[0, 1], cmap=cmap, norm=norm)
338338
plt.colorbar()
339+
340+
341+
def test_auto_papersize_deprecation():
342+
fig = plt.figure()
343+
with pytest.warns(mpl.MatplotlibDeprecationWarning):
344+
fig.savefig(io.BytesIO(), format='eps', papertype='auto')
345+
346+
with pytest.warns(mpl.MatplotlibDeprecationWarning):
347+
mpl.rcParams['ps.papersize'] = 'auto'

0 commit comments

Comments
 (0)