Skip to content

Commit 7634823

Browse files
authored
Merge pull request matplotlib#20235 from aitikgupta/warn-mathtext
2 parents c56e3c5 + 7a8aa99 commit 7634823

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,18 @@ def test_cursor_dummy_axis(self, data, expected):
577577
fmt = sf.format_data_short
578578
assert fmt(data) == expected
579579

580+
def test_mathtext_ticks(self):
581+
mpl.rcParams.update({
582+
'font.family': 'serif',
583+
'font.serif': 'cmr10',
584+
'axes.formatter.use_mathtext': False
585+
})
586+
587+
with pytest.warns(UserWarning, match='cmr10 font should ideally'):
588+
fig, ax = plt.subplots()
589+
ax.set_xticks([-1, 0, 1])
590+
fig.canvas.draw()
591+
580592

581593
class FakeAxis:
582594
"""Allow Formatter to be called without having a "full" plot set up."""

lib/matplotlib/ticker.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,22 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
475475
self._usetex = mpl.rcParams['text.usetex']
476476
if useMathText is None:
477477
useMathText = mpl.rcParams['axes.formatter.use_mathtext']
478+
if useMathText is False:
479+
try:
480+
ufont = mpl.font_manager.findfont(
481+
mpl.font_manager.FontProperties(
482+
mpl.rcParams["font.family"]
483+
),
484+
fallback_to_default=False,
485+
)
486+
except ValueError:
487+
ufont = None
488+
489+
if ufont == str(cbook._get_data_path("fonts/ttf/cmr10.ttf")):
490+
_api.warn_external(
491+
"cmr10 font should ideally be used with "
492+
"mathtext, set axes.formatter.use_mathtext to True"
493+
)
478494
self.set_useMathText(useMathText)
479495
self.orderOfMagnitude = 0
480496
self.format = ''

0 commit comments

Comments
 (0)