Skip to content

Commit 860803d

Browse files
authored
Merge pull request #16165 from anntzer/31rc
MNT: Remove rcParams deprecated in mpl3.0/3.1.
2 parents 033bc3b + e8f6f4c commit 860803d

File tree

9 files changed

+36
-95
lines changed

9 files changed

+36
-95
lines changed

doc/api/next_api_changes/removals.rst

+11
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,14 @@ Arguments
115115
- The parameter ``usetex`` of `.TextToPath.get_text_path` has been removed.
116116
Use ``ismath='TeX'`` instead.
117117
- The parameter ``block`` of ``show()`` is now keyword-only.
118+
- The parameter ``frameon`` of `.Figure.savefig` has been removed. Use
119+
``facecolor="none"`` to get a transparent background.
120+
121+
rcParams
122+
~~~~~~~~
123+
- The ``text.latex.unicode`` rcParam has been removed, with no replacement.
124+
Matplotlib now always supports unicode in usetex.
125+
- The ``savefig.frameon`` rcParam has been removed. Set
126+
:rc:`savefig.facecolor` to "none" to get a transparent background.
127+
- The ``pgf.debug``, ``verbose.fileo`` and ``verbose.verbose.level`` rcParams,
128+
which had no effect, have been removed.

examples/misc/custom_projection.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ def __init__(self, round_to=1.0):
4040

4141
def __call__(self, x, pos=None):
4242
degrees = round(np.rad2deg(x) / self._round_to) * self._round_to
43-
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
44-
return r"$%0.0f^\circ$" % degrees
45-
else:
46-
return "%0.0f\N{DEGREE SIGN}" % degrees
43+
return f"{degrees:0.0f}\N{DEGREE SIGN}"
4744

4845
RESOLUTION = 75
4946

lib/matplotlib/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,12 @@ def gen_candidates():
611611
# rcParams deprecated; some can manually be mapped to another key.
612612
# Values are tuples of (version, new_name_or_None).
613613
_deprecated_ignore_map = {
614-
'pgf.debug': ('3.0', None),
615614
}
616615

617616
# rcParams deprecated; can use None to suppress warnings; remain actually
618617
# listed in the rcParams (not included in _all_deprecated).
619618
# Values are tuples of (version,)
620619
_deprecated_remain_as_none = {
621-
'text.latex.unicode': ('3.0',),
622-
'savefig.frameon': ('3.1',),
623-
'verbose.fileo': ('3.1',),
624-
'verbose.level': ('3.1',),
625620
}
626621

627622

lib/matplotlib/figure.py

-15
Original file line numberDiff line numberDiff line change
@@ -2149,14 +2149,6 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21492149
"""
21502150

21512151
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
2152-
if "frameon" in kwargs:
2153-
cbook.warn_deprecated("3.1", name="frameon", obj_type="kwarg",
2154-
alternative="facecolor")
2155-
frameon = kwargs.pop("frameon")
2156-
if frameon is None:
2157-
frameon = dict.__getitem__(rcParams, 'savefig.frameon')
2158-
else:
2159-
frameon = False # Won't pass "if frameon:" below.
21602152
if transparent is None:
21612153
transparent = rcParams['savefig.transparent']
21622154

@@ -2174,15 +2166,8 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21742166
kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
21752167
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
21762168

2177-
if frameon:
2178-
original_frameon = self.patch.get_visible()
2179-
self.patch.set_visible(frameon)
2180-
21812169
self.canvas.print_figure(fname, **kwargs)
21822170

2183-
if frameon:
2184-
self.patch.set_visible(original_frameon)
2185-
21862171
if transparent:
21872172
for ax, cc in zip(self.axes, original_axes_colors):
21882173
ax.patch.set_facecolor(cc[0])

lib/matplotlib/projections/geo.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class GeoAxes(Axes):
1515
"""An abstract base class for geographic projections."""
16+
1617
class ThetaFormatter(Formatter):
1718
"""
1819
Used to format the theta tick labels. Converts the native
@@ -23,10 +24,7 @@ def __init__(self, round_to=1.0):
2324

2425
def __call__(self, x, pos=None):
2526
degrees = round(np.rad2deg(x) / self._round_to) * self._round_to
26-
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
27-
return r"$%0.0f^\circ$" % degrees
28-
else:
29-
return "%0.0f\N{DEGREE SIGN}" % degrees
27+
return f"{degrees:0.0f}\N{DEGREE SIGN}"
3028

3129
RESOLUTION = 75
3230

lib/matplotlib/projections/polar.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,12 @@ def __call__(self, x, pos=None):
165165
vmin, vmax = self.axis.get_view_interval()
166166
d = np.rad2deg(abs(vmax - vmin))
167167
digits = max(-int(np.log10(d) - 1.5), 0)
168-
169-
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
170-
format_str = r"${value:0.{digits:d}f}^\circ$"
171-
return format_str.format(value=np.rad2deg(x), digits=digits)
172-
else:
173-
# we use unicode, rather than mathtext with \circ, so
174-
# that it will work correctly with any arbitrary font
175-
# (assuming it has a degree sign), whereas $5\circ$
176-
# will only work correctly with one of the supported
177-
# math fonts (Computer Modern and STIX)
178-
format_str = "{value:0.{digits:d}f}\N{DEGREE SIGN}"
179-
return format_str.format(value=np.rad2deg(x), digits=digits)
168+
# Use unicode rather than mathtext with \circ, so that it will work
169+
# correctly with any arbitrary font (assuming it has a degree sign),
170+
# whereas $5\circ$ will only work correctly with one of the supported
171+
# math fonts (Computer Modern and STIX).
172+
return ("{value:0.{digits:d}f}\N{DEGREE SIGN}"
173+
.format(value=np.rad2deg(x), digits=digits))
180174

181175

182176
class _AxisWrapper:

lib/matplotlib/rcsetup.py

-12
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,6 @@ def validate_mathtext_default(s):
441441
'center_baseline'])
442442

443443

444-
_validate_verbose = ValidateInStrings(
445-
'verbose',
446-
['silent', 'helpful', 'debug', 'debug-annoying'])
447-
448-
449444
def validate_whiskers(s):
450445
if s == 'range':
451446
cbook.warn_deprecated(
@@ -1013,10 +1008,6 @@ def validate_webagg_address(s):
10131008
'interactive': [False, validate_bool],
10141009
'timezone': ['UTC', validate_string],
10151010

1016-
# the verbosity setting
1017-
'verbose.level': ['silent', _validate_verbose],
1018-
'verbose.fileo': ['sys.stdout', validate_string],
1019-
10201011
# line props
10211012
'lines.linewidth': [1.5, validate_float], # line width in points
10221013
'lines.linestyle': ['-', _validate_linestyle], # solid line
@@ -1133,7 +1124,6 @@ def validate_webagg_address(s):
11331124
# text props
11341125
'text.color': ['black', validate_color],
11351126
'text.usetex': [False, validate_bool],
1136-
'text.latex.unicode': [True, validate_bool],
11371127
'text.latex.preamble': ['', _validate_tex_preamble],
11381128
'text.latex.preview': [False, validate_bool],
11391129
'text.hinting': ['auto', validate_hinting],
@@ -1364,7 +1354,6 @@ def validate_webagg_address(s):
13641354
'savefig.dpi': ['figure', validate_dpi], # DPI
13651355
'savefig.facecolor': ['white', validate_color],
13661356
'savefig.edgecolor': ['white', validate_color],
1367-
'savefig.frameon': [True, validate_bool],
13681357
'savefig.orientation': ['portrait', validate_orientation],
13691358
'savefig.jpeg_quality': [95, validate_int],
13701359
# value checked by backend at runtime
@@ -1394,7 +1383,6 @@ def validate_webagg_address(s):
13941383
'pdf.use14corefonts': [False, validate_bool],
13951384
'pdf.fonttype': [3, validate_fonttype], # 3 (Type3) or 42 (Truetype)
13961385

1397-
'pgf.debug': [False, validate_bool], # output debug information
13981386
# choose latex application for creating pdf files (xelatex/lualatex)
13991387
'pgf.texsystem': ['xelatex', validate_pgf_texsystem],
14001388
# use matplotlib rc settings for font configuration

lib/matplotlib/texmanager.py

+13-34
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class TexManager:
8787
'computer modern typewriter': ('cmtt', r'\usepackage{type1ec}')}
8888

8989
_rc_cache = None
90-
_rc_cache_keys = (
91-
('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview',
92-
'font.family') + tuple('font.' + n for n in font_families))
90+
_rc_cache_keys = [
91+
'text.latex.preamble', 'text.latex.preview', 'font.family',
92+
*['font.' + n for n in font_families]]
9393

9494
@cbook.deprecated("3.3", alternative="matplotlib.get_cachedir()")
9595
@property
@@ -184,18 +184,15 @@ def get_custom_preamble(self):
184184
return rcParams['text.latex.preamble']
185185

186186
def _get_preamble(self):
187-
unicode_preamble = "\n".join([
188-
r"\usepackage[utf8]{inputenc}",
189-
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
190-
]) if rcParams["text.latex.unicode"] else ""
191187
return "\n".join([
192188
r"\documentclass{article}",
193189
# Pass-through \mathdefault, which is used in non-usetex mode to
194190
# use the default text font but was historically suppressed in
195191
# usetex mode.
196192
r"\newcommand{\mathdefault}[1]{#1}",
197193
self._font_preamble,
198-
unicode_preamble,
194+
r"\usepackage[utf8]{inputenc}",
195+
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
199196
self.get_custom_preamble(),
200197
])
201198

@@ -210,26 +207,17 @@ def make_tex(self, tex, fontsize):
210207
fontcmd = {'sans-serif': r'{\sffamily %s}',
211208
'monospace': r'{\ttfamily %s}'}.get(self.font_family,
212209
r'{\rmfamily %s}')
213-
tex = fontcmd % tex
214210

215-
s = r"""
211+
Path(texfile).write_text(
212+
r"""
216213
%s
217214
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
218215
\pagestyle{empty}
219216
\begin{document}
220217
\fontsize{%f}{%f}%s
221218
\end{document}
222-
""" % (self._get_preamble(), fontsize, fontsize * 1.25, tex)
223-
with open(texfile, 'wb') as fh:
224-
if rcParams['text.latex.unicode']:
225-
fh.write(s.encode('utf8'))
226-
else:
227-
try:
228-
fh.write(s.encode('ascii'))
229-
except UnicodeEncodeError:
230-
_log.info("You are using unicode and latex, but have not "
231-
"enabled the 'text.latex.unicode' rcParam.")
232-
raise
219+
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
220+
encoding='utf-8')
233221

234222
return texfile
235223

@@ -250,12 +238,12 @@ def make_tex_preview(self, tex, fontsize):
250238
fontcmd = {'sans-serif': r'{\sffamily %s}',
251239
'monospace': r'{\ttfamily %s}'}.get(self.font_family,
252240
r'{\rmfamily %s}')
253-
tex = fontcmd % tex
254241

255242
# newbox, setbox, immediate, etc. are used to find the box
256243
# extent of the rendered text.
257244

258-
s = r"""
245+
Path(texfile).write_text(
246+
r"""
259247
%s
260248
\usepackage[active,showbox,tightpage]{preview}
261249
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
@@ -270,17 +258,8 @@ def make_tex_preview(self, tex, fontsize):
270258
{\fontsize{%f}{%f}%s}
271259
\end{preview}
272260
\end{document}
273-
""" % (self._get_preamble(), fontsize, fontsize * 1.25, tex)
274-
with open(texfile, 'wb') as fh:
275-
if rcParams['text.latex.unicode']:
276-
fh.write(s.encode('utf8'))
277-
else:
278-
try:
279-
fh.write(s.encode('ascii'))
280-
except UnicodeEncodeError:
281-
_log.info("You are using unicode and latex, but have not "
282-
"enabled the 'text.latex.unicode' rcParam.")
283-
raise
261+
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
262+
encoding='utf-8')
284263

285264
return texfile
286265

lib/matplotlib/ticker.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,9 @@ def fix_minus(s):
284284
helper method to perform such a replacement when it is enabled via
285285
:rc:`axes.unicode_minus`.
286286
"""
287-
# Additionally, we disable the replacement when using usetex without
288-
# unicode support (this is deprecated, i.e., in a future version,
289-
# unicode support will always be enabled).
290-
if (rcParams['axes.unicode_minus']
291-
and (rcParams['text.latex.unicode']
292-
or not rcParams['text.usetex'])):
293-
return s.replace('-', '\N{MINUS SIGN}')
294-
else:
295-
return s
287+
return (s.replace('-', '\N{MINUS SIGN}')
288+
if rcParams['axes.unicode_minus']
289+
else s)
296290

297291
def _set_locator(self, locator):
298292
"""Subclasses may want to override this to set a locator."""

0 commit comments

Comments
 (0)