diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 2a6719e2fd3c..56ca73905cc5 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -577,6 +577,18 @@ def test_cursor_dummy_axis(self, data, expected): fmt = sf.format_data_short assert fmt(data) == expected + def test_mathtext_ticks(self): + mpl.rcParams.update({ + 'font.family': 'serif', + 'font.serif': 'cmr10', + 'axes.formatter.use_mathtext': False + }) + + with pytest.warns(UserWarning, match='cmr10 font should ideally'): + fig, ax = plt.subplots() + ax.set_xticks([-1, 0, 1]) + fig.canvas.draw() + class FakeAxis: """Allow Formatter to be called without having a "full" plot set up.""" diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 2473bee2b0a0..2831069ab222 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -475,6 +475,22 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None): self._usetex = mpl.rcParams['text.usetex'] if useMathText is None: useMathText = mpl.rcParams['axes.formatter.use_mathtext'] + if useMathText is False: + try: + ufont = mpl.font_manager.findfont( + mpl.font_manager.FontProperties( + mpl.rcParams["font.family"] + ), + fallback_to_default=False, + ) + except ValueError: + ufont = None + + if ufont == str(cbook._get_data_path("fonts/ttf/cmr10.ttf")): + _api.warn_external( + "cmr10 font should ideally be used with " + "mathtext, set axes.formatter.use_mathtext to True" + ) self.set_useMathText(useMathText) self.orderOfMagnitude = 0 self.format = '' pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy