Skip to content

Commit 0569b27

Browse files
committed
Remove rcParams deprecated in mpl3.0/3.1.
1 parent 65349e1 commit 0569b27

File tree

9 files changed

+34
-84
lines changed

9 files changed

+34
-84
lines changed

doc/api/next_api_changes/removals.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,12 @@ 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.

examples/misc/custom_projection.py

Lines changed: 1 addition & 4 deletions
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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,12 @@ def gen_candidates():
616616
# rcParams deprecated; some can manually be mapped to another key.
617617
# Values are tuples of (version, new_name_or_None).
618618
_deprecated_ignore_map = {
619-
'pgf.debug': ('3.0', None),
620619
}
621620

622621
# rcParams deprecated; can use None to suppress warnings; remain actually
623622
# listed in the rcParams (not included in _all_deprecated).
624623
# Values are tuples of (version,)
625624
_deprecated_remain_as_none = {
626-
'text.latex.unicode': ('3.0',),
627-
'savefig.frameon': ('3.1',),
628-
'verbose.fileo': ('3.1',),
629-
'verbose.level': ('3.1',),
630625
}
631626

632627

lib/matplotlib/figure.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,14 +2152,6 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21522152
"""
21532153

21542154
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
2155-
if "frameon" in kwargs:
2156-
cbook.warn_deprecated("3.1", name="frameon", obj_type="kwarg",
2157-
alternative="facecolor")
2158-
frameon = kwargs.pop("frameon")
2159-
if frameon is None:
2160-
frameon = dict.__getitem__(rcParams, 'savefig.frameon')
2161-
else:
2162-
frameon = False # Won't pass "if frameon:" below.
21632155
if transparent is None:
21642156
transparent = rcParams['savefig.transparent']
21652157

@@ -2177,15 +2169,8 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21772169
kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
21782170
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
21792171

2180-
if frameon:
2181-
original_frameon = self.patch.get_visible()
2182-
self.patch.set_visible(frameon)
2183-
21842172
self.canvas.print_figure(fname, **kwargs)
21852173

2186-
if frameon:
2187-
self.patch.set_visible(original_frameon)
2188-
21892174
if transparent:
21902175
for ax, cc in zip(self.axes, original_axes_colors):
21912176
ax.patch.set_facecolor(cc[0])

lib/matplotlib/projections/geo.py

Lines changed: 2 additions & 4 deletions
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

Lines changed: 6 additions & 12 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ def validate_webagg_address(s):
11331133
# text props
11341134
'text.color': ['black', validate_color],
11351135
'text.usetex': [False, validate_bool],
1136-
'text.latex.unicode': [True, validate_bool],
11371136
'text.latex.preamble': ['', _validate_tex_preamble],
11381137
'text.latex.preview': [False, validate_bool],
11391138
'text.hinting': ['auto', validate_hinting],

lib/matplotlib/texmanager.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class TexManager:
9595
'computer modern typewriter': ('cmtt', r'\usepackage{type1ec}')}
9696

9797
_rc_cache = None
98-
_rc_cache_keys = (
99-
('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview',
100-
'font.family') + tuple('font.' + n for n in font_families))
98+
_rc_cache_keys = [
99+
'text.latex.preamble', 'text.latex.preview', 'font.family',
100+
*['font.' + n for n in font_families]]
101101

102102
@functools.lru_cache() # Always return the same instance.
103103
def __new__(cls):
@@ -193,18 +193,15 @@ def get_custom_preamble(self):
193193
return rcParams['text.latex.preamble']
194194

195195
def _get_preamble(self):
196-
unicode_preamble = "\n".join([
197-
r"\usepackage[utf8]{inputenc}",
198-
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
199-
]) if rcParams["text.latex.unicode"] else ""
200196
return "\n".join([
201197
r"\documentclass{article}",
202198
# Pass-through \mathdefault, which is used in non-usetex mode to
203199
# use the default text font but was historically suppressed in
204200
# usetex mode.
205201
r"\newcommand{\mathdefault}[1]{#1}",
206202
self._font_preamble,
207-
unicode_preamble,
203+
r"\usepackage[utf8]{inputenc}",
204+
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
208205
self.get_custom_preamble(),
209206
])
210207

@@ -219,26 +216,17 @@ def make_tex(self, tex, fontsize):
219216
fontcmd = {'sans-serif': r'{\sffamily %s}',
220217
'monospace': r'{\ttfamily %s}'}.get(self.font_family,
221218
r'{\rmfamily %s}')
222-
tex = fontcmd % tex
223219

224-
s = r"""
220+
Path(texfile).write_text(
221+
r"""
225222
%s
226223
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
227224
\pagestyle{empty}
228225
\begin{document}
229226
\fontsize{%f}{%f}%s
230227
\end{document}
231-
""" % (self._get_preamble(), fontsize, fontsize * 1.25, tex)
232-
with open(texfile, 'wb') as fh:
233-
if rcParams['text.latex.unicode']:
234-
fh.write(s.encode('utf8'))
235-
else:
236-
try:
237-
fh.write(s.encode('ascii'))
238-
except UnicodeEncodeError:
239-
_log.info("You are using unicode and latex, but have not "
240-
"enabled the 'text.latex.unicode' rcParam.")
241-
raise
228+
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
229+
encoding='utf-8')
242230

243231
return texfile
244232

@@ -259,12 +247,12 @@ def make_tex_preview(self, tex, fontsize):
259247
fontcmd = {'sans-serif': r'{\sffamily %s}',
260248
'monospace': r'{\ttfamily %s}'}.get(self.font_family,
261249
r'{\rmfamily %s}')
262-
tex = fontcmd % tex
263250

264251
# newbox, setbox, immediate, etc. are used to find the box
265252
# extent of the rendered text.
266253

267-
s = r"""
254+
Path(texfile).write_text(
255+
r"""
268256
%s
269257
\usepackage[active,showbox,tightpage]{preview}
270258
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
@@ -279,17 +267,8 @@ def make_tex_preview(self, tex, fontsize):
279267
{\fontsize{%f}{%f}%s}
280268
\end{preview}
281269
\end{document}
282-
""" % (self._get_preamble(), fontsize, fontsize * 1.25, tex)
283-
with open(texfile, 'wb') as fh:
284-
if rcParams['text.latex.unicode']:
285-
fh.write(s.encode('utf8'))
286-
else:
287-
try:
288-
fh.write(s.encode('ascii'))
289-
except UnicodeEncodeError:
290-
_log.info("You are using unicode and latex, but have not "
291-
"enabled the 'text.latex.unicode' rcParam.")
292-
raise
270+
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
271+
encoding='utf-8')
293272

294273
return texfile
295274

lib/matplotlib/ticker.py

Lines changed: 3 additions & 9 deletions
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)