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 0615b80

Browse filesBrowse files
committed
Deprecate automatic papersize in PostScript
This automation is not very good, and just saving at the figure size is better for EPS. Closes #7551
1 parent cf02034 commit 0615b80
Copy full SHA for 0615b80

File tree

Expand file treeCollapse file tree

4 files changed

+36
-5
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-5
lines changed
+6Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,10 @@ def _print_figure(
867867
# find the appropriate papertype
868868
width, height = self.figure.get_size_inches()
869869
if papertype == 'auto':
870-
papertype = _get_papertype(
871-
*orientation.swap_if_landscape((width, height)))
870+
_api.warn_deprecated("3.8", name="papertype='auto'",
871+
addendum="Pass an explicit paper type, or omit the "
872+
"*papertype* argument entirely.")
873+
papertype = _get_papertype(*orientation.swap_if_landscape((width, height)))
872874

873875
if is_eps:
874876
paper_width, paper_height = width, height
@@ -1059,6 +1061,9 @@ def _print_figure_tex(
10591061
self.figure.get_size_inches())
10601062
else:
10611063
if papertype == 'auto':
1064+
_api.warn_deprecated("3.8", name="papertype='auto'",
1065+
addendum="Pass an explicit paper type, or "
1066+
"omit the *papertype* argument entirely.")
10621067
papertype = _get_papertype(width, height)
10631068
paper_width, paper_height = papersize[papertype]
10641069

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+14-3Lines 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(
@@ -1180,9 +1193,7 @@ def _convert_validator_spec(key, conv):
11801193
"tk.window_focus": validate_bool, # Maintain shell focus for TkAgg
11811194

11821195
# Set the papersize/type
1183-
"ps.papersize": _ignorecase(["auto", "letter", "legal", "ledger",
1184-
*[f"{ab}{i}"
1185-
for ab in "ab" for i in range(11)]]),
1196+
"ps.papersize": _validate_papersize,
11861197
"ps.useafm": validate_bool,
11871198
# use ghostscript or xpdf to distill ps output
11881199
"ps.usedistiller": validate_ps_distiller,

‎lib/matplotlib/tests/test_backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_ps.py
+9Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.