diff --git a/doc/api/next_api_changes/removals.rst b/doc/api/next_api_changes/removals.rst index 9b21206f6f87..8c41ada50790 100644 --- a/doc/api/next_api_changes/removals.rst +++ b/doc/api/next_api_changes/removals.rst @@ -115,3 +115,14 @@ Arguments - The parameter ``usetex`` of `.TextToPath.get_text_path` has been removed. Use ``ismath='TeX'`` instead. - The parameter ``block`` of ``show()`` is now keyword-only. +- The parameter ``frameon`` of `.Figure.savefig` has been removed. Use + ``facecolor="none"`` to get a transparent background. + +rcParams +~~~~~~~~ +- The ``text.latex.unicode`` rcParam has been removed, with no replacement. + Matplotlib now always supports unicode in usetex. +- The ``savefig.frameon`` rcParam has been removed. Set + :rc:`savefig.facecolor` to "none" to get a transparent background. +- The ``pgf.debug``, ``verbose.fileo`` and ``verbose.verbose.level`` rcParams, + which had no effect, have been removed. diff --git a/examples/misc/custom_projection.py b/examples/misc/custom_projection.py index c0e3ea2ad842..cfc37613e566 100644 --- a/examples/misc/custom_projection.py +++ b/examples/misc/custom_projection.py @@ -40,10 +40,7 @@ def __init__(self, round_to=1.0): def __call__(self, x, pos=None): degrees = round(np.rad2deg(x) / self._round_to) * self._round_to - if rcParams['text.usetex'] and not rcParams['text.latex.unicode']: - return r"$%0.0f^\circ$" % degrees - else: - return "%0.0f\N{DEGREE SIGN}" % degrees + return f"{degrees:0.0f}\N{DEGREE SIGN}" RESOLUTION = 75 diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 00e97ad9f91b..280e8d5fd123 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -616,17 +616,12 @@ def gen_candidates(): # rcParams deprecated; some can manually be mapped to another key. # Values are tuples of (version, new_name_or_None). _deprecated_ignore_map = { - 'pgf.debug': ('3.0', None), } # rcParams deprecated; can use None to suppress warnings; remain actually # listed in the rcParams (not included in _all_deprecated). # Values are tuples of (version,) _deprecated_remain_as_none = { - 'text.latex.unicode': ('3.0',), - 'savefig.frameon': ('3.1',), - 'verbose.fileo': ('3.1',), - 'verbose.level': ('3.1',), } diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 4b44632ed9c7..6e55db2b9fdd 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2152,14 +2152,6 @@ def savefig(self, fname, *, transparent=None, **kwargs): """ kwargs.setdefault('dpi', rcParams['savefig.dpi']) - if "frameon" in kwargs: - cbook.warn_deprecated("3.1", name="frameon", obj_type="kwarg", - alternative="facecolor") - frameon = kwargs.pop("frameon") - if frameon is None: - frameon = dict.__getitem__(rcParams, 'savefig.frameon') - else: - frameon = False # Won't pass "if frameon:" below. if transparent is None: transparent = rcParams['savefig.transparent'] @@ -2177,15 +2169,8 @@ def savefig(self, fname, *, transparent=None, **kwargs): kwargs.setdefault('facecolor', rcParams['savefig.facecolor']) kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor']) - if frameon: - original_frameon = self.patch.get_visible() - self.patch.set_visible(frameon) - self.canvas.print_figure(fname, **kwargs) - if frameon: - self.patch.set_visible(original_frameon) - if transparent: for ax, cc in zip(self.axes, original_axes_colors): ax.patch.set_facecolor(cc[0]) diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index 57d6a486f9cf..c973d0402b9d 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -13,6 +13,7 @@ class GeoAxes(Axes): """An abstract base class for geographic projections.""" + class ThetaFormatter(Formatter): """ Used to format the theta tick labels. Converts the native @@ -23,10 +24,7 @@ def __init__(self, round_to=1.0): def __call__(self, x, pos=None): degrees = round(np.rad2deg(x) / self._round_to) * self._round_to - if rcParams['text.usetex'] and not rcParams['text.latex.unicode']: - return r"$%0.0f^\circ$" % degrees - else: - return "%0.0f\N{DEGREE SIGN}" % degrees + return f"{degrees:0.0f}\N{DEGREE SIGN}" RESOLUTION = 75 diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 1ad32c63c3fc..ad31776eb025 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -165,18 +165,12 @@ def __call__(self, x, pos=None): vmin, vmax = self.axis.get_view_interval() d = np.rad2deg(abs(vmax - vmin)) digits = max(-int(np.log10(d) - 1.5), 0) - - if rcParams['text.usetex'] and not rcParams['text.latex.unicode']: - format_str = r"${value:0.{digits:d}f}^\circ$" - return format_str.format(value=np.rad2deg(x), digits=digits) - else: - # we use unicode, rather than mathtext with \circ, so - # that it will work correctly with any arbitrary font - # (assuming it has a degree sign), whereas $5\circ$ - # will only work correctly with one of the supported - # math fonts (Computer Modern and STIX) - format_str = "{value:0.{digits:d}f}\N{DEGREE SIGN}" - return format_str.format(value=np.rad2deg(x), digits=digits) + # Use unicode rather than mathtext with \circ, so that it will work + # correctly with any arbitrary font (assuming it has a degree sign), + # whereas $5\circ$ will only work correctly with one of the supported + # math fonts (Computer Modern and STIX). + return ("{value:0.{digits:d}f}\N{DEGREE SIGN}" + .format(value=np.rad2deg(x), digits=digits)) class _AxisWrapper: diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index ac77feae4385..6d81faee599f 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -441,11 +441,6 @@ def validate_mathtext_default(s): 'center_baseline']) -_validate_verbose = ValidateInStrings( - 'verbose', - ['silent', 'helpful', 'debug', 'debug-annoying']) - - def validate_whiskers(s): if s == 'range': cbook.warn_deprecated( @@ -1013,10 +1008,6 @@ def validate_webagg_address(s): 'interactive': [False, validate_bool], 'timezone': ['UTC', validate_string], - # the verbosity setting - 'verbose.level': ['silent', _validate_verbose], - 'verbose.fileo': ['sys.stdout', validate_string], - # line props 'lines.linewidth': [1.5, validate_float], # line width in points 'lines.linestyle': ['-', _validate_linestyle], # solid line @@ -1133,7 +1124,6 @@ def validate_webagg_address(s): # text props 'text.color': ['black', validate_color], 'text.usetex': [False, validate_bool], - 'text.latex.unicode': [True, validate_bool], 'text.latex.preamble': ['', _validate_tex_preamble], 'text.latex.preview': [False, validate_bool], 'text.hinting': ['auto', validate_hinting], @@ -1364,7 +1354,6 @@ def validate_webagg_address(s): 'savefig.dpi': ['figure', validate_dpi], # DPI 'savefig.facecolor': ['white', validate_color], 'savefig.edgecolor': ['white', validate_color], - 'savefig.frameon': [True, validate_bool], 'savefig.orientation': ['portrait', validate_orientation], 'savefig.jpeg_quality': [95, validate_int], # value checked by backend at runtime @@ -1394,7 +1383,6 @@ def validate_webagg_address(s): 'pdf.use14corefonts': [False, validate_bool], 'pdf.fonttype': [3, validate_fonttype], # 3 (Type3) or 42 (Truetype) - 'pgf.debug': [False, validate_bool], # output debug information # choose latex application for creating pdf files (xelatex/lualatex) 'pgf.texsystem': ['xelatex', validate_pgf_texsystem], # use matplotlib rc settings for font configuration diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index bdbb38d711d9..bde0d514aae7 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -95,9 +95,9 @@ class TexManager: 'computer modern typewriter': ('cmtt', r'\usepackage{type1ec}')} _rc_cache = None - _rc_cache_keys = ( - ('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview', - 'font.family') + tuple('font.' + n for n in font_families)) + _rc_cache_keys = [ + 'text.latex.preamble', 'text.latex.preview', 'font.family', + *['font.' + n for n in font_families]] @functools.lru_cache() # Always return the same instance. def __new__(cls): @@ -193,10 +193,6 @@ def get_custom_preamble(self): return rcParams['text.latex.preamble'] def _get_preamble(self): - unicode_preamble = "\n".join([ - r"\usepackage[utf8]{inputenc}", - r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}", - ]) if rcParams["text.latex.unicode"] else "" return "\n".join([ r"\documentclass{article}", # Pass-through \mathdefault, which is used in non-usetex mode to @@ -204,7 +200,8 @@ def _get_preamble(self): # usetex mode. r"\newcommand{\mathdefault}[1]{#1}", self._font_preamble, - unicode_preamble, + r"\usepackage[utf8]{inputenc}", + r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}", self.get_custom_preamble(), ]) @@ -219,26 +216,17 @@ def make_tex(self, tex, fontsize): fontcmd = {'sans-serif': r'{\sffamily %s}', 'monospace': r'{\ttfamily %s}'}.get(self.font_family, r'{\rmfamily %s}') - tex = fontcmd % tex - s = r""" + Path(texfile).write_text( + r""" %s \usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry} \pagestyle{empty} \begin{document} \fontsize{%f}{%f}%s \end{document} -""" % (self._get_preamble(), fontsize, fontsize * 1.25, tex) - with open(texfile, 'wb') as fh: - if rcParams['text.latex.unicode']: - fh.write(s.encode('utf8')) - else: - try: - fh.write(s.encode('ascii')) - except UnicodeEncodeError: - _log.info("You are using unicode and latex, but have not " - "enabled the 'text.latex.unicode' rcParam.") - raise +""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex), + encoding='utf-8') return texfile @@ -259,12 +247,12 @@ def make_tex_preview(self, tex, fontsize): fontcmd = {'sans-serif': r'{\sffamily %s}', 'monospace': r'{\ttfamily %s}'}.get(self.font_family, r'{\rmfamily %s}') - tex = fontcmd % tex # newbox, setbox, immediate, etc. are used to find the box # extent of the rendered text. - s = r""" + Path(texfile).write_text( + r""" %s \usepackage[active,showbox,tightpage]{preview} \usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry} @@ -279,17 +267,8 @@ def make_tex_preview(self, tex, fontsize): {\fontsize{%f}{%f}%s} \end{preview} \end{document} -""" % (self._get_preamble(), fontsize, fontsize * 1.25, tex) - with open(texfile, 'wb') as fh: - if rcParams['text.latex.unicode']: - fh.write(s.encode('utf8')) - else: - try: - fh.write(s.encode('ascii')) - except UnicodeEncodeError: - _log.info("You are using unicode and latex, but have not " - "enabled the 'text.latex.unicode' rcParam.") - raise +""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex), + encoding='utf-8') return texfile diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 6f8406e8a0a4..4d0f1a55ebc9 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -284,15 +284,9 @@ def fix_minus(s): helper method to perform such a replacement when it is enabled via :rc:`axes.unicode_minus`. """ - # Additionally, we disable the replacement when using usetex without - # unicode support (this is deprecated, i.e., in a future version, - # unicode support will always be enabled). - if (rcParams['axes.unicode_minus'] - and (rcParams['text.latex.unicode'] - or not rcParams['text.usetex'])): - return s.replace('-', '\N{MINUS SIGN}') - else: - return s + return (s.replace('-', '\N{MINUS SIGN}') + if rcParams['axes.unicode_minus'] + else s) def _set_locator(self, locator): """Subclasses may want to override this to set a locator."""