Skip to content

Commit 5ce23a5

Browse files
committed
Remove mathtext_fallback figure keyword
1 parent f2b16b5 commit 5ce23a5

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

docs/fonts.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,23 @@
6767
# :ref:`default proplotrc file <ug_proplotrc>`.
6868
#
6969
# To compare different fonts, use the `~proplot.demos.show_fonts` command with the
70-
# `family` keyword (default behavior is ``family='sans-serif'``). Tables of the
71-
# TeX Gyre and sans-serif fonts packaged with proplot are shown below. The "¤" symbol
72-
# appears where characters for a particular font are unavailable (when making plots,
73-
# "¤" is replaced with the character from a fallback font). Since most TeX Gyre fonts
74-
# have limited character sets, if your plots contain lots of mathematical symbols,
75-
# you may want to set :rcraw:`font.family` to the matplotlib-packaged
76-
# font ``'DejaVu Sans'`` or the proplot-packaged font ``'Fira Math'``
77-
# (see `this page <https://github.com/firamath/firamath>`__ for more on Fira Math).
70+
# `family` keyword (default behavior is ``family='sans-serif'``). Tables of the TeX
71+
# Gyre and sans-serif fonts packaged with proplot are shown below. In order to show how
72+
# the fonts perform as math text, the demo is rendered with :rcraw:`mathtext.default`
73+
# = ``'regular'``, :rcraw:`mathtext.fontset` = ``'custom'``, and
74+
# :rcraw:`mathtext.fallback` = ``None``. This uses the global :rcraw:`font.family`
75+
# for the math text and shows a dummy glyph "¤" is shown where math characters
76+
# are unavailable (see the matplotlib `math text guide
77+
# <https://matplotlib.org/stable/tutorials/text/mathtext.html#custom-fonts>`__
78+
# for details). In practice, proplot uses a standard non-italicized math
79+
# text everywhere by setting :rc:`mathtext.fontset` = ``'stixsans'`` and
80+
# :rcraw:`mathtext.default = 'rm'` (see the :ref:`proplotrc file <ug_proplotrc>`
81+
# for details).
7882
#
7983
# .. note::
8084
#
81-
# Try to avoid ``.ttf`` files with ``Thin`` in the file name. Some versions of
82-
# matplotlib interpret fonts with the "thin" style as having *normal* weight (see
85+
# Try to avoid "thin" ``.ttf`` files. Some versions of matplotlib
86+
# interpret fonts with the "thin" style as having *normal* weight (see
8387
# `this issue page <https://github.com/matplotlib/matplotlib/issues/8788>`__),
8488
# causing them to override the correct normal weight versions. While proplot
8589
# tries to filter out these files, this cannot be done systematically. In the

proplot/axes/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,6 @@
387387
Whether to include panels when aligning figure "super titles" along the top
388388
of the subplot grid and when aligning the `spanx` *x* axis labels and
389389
`spany` *y* axis labels along the sides of the subplot grid.
390-
mathtext_fallback : bool or str, default: :rc:`mathtext.fallback`
391-
Apply this :rcraw:`mathtext.fallback` value when drawing the figure. If
392-
``True`` or string, unavailable glyphs are replaced with a glyph from a
393-
fallback font (Computer Modern by default). Otherwise, they are replaced
394-
with the "¤" dummy character. For details see this `mathtext tutorial \
395-
<https://matplotlib.org/stable/tutorials/text/mathtext.html#custom-fonts>`__.
396390
"""
397391
_rc_init_docstring = """
398392
"""

proplot/demos.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from . import constructor, ui
1515
from .config import _get_data_folders, rc
1616
from .internals import ic # noqa: F401
17-
from .internals import _not_none, docstring, warnings
17+
from .internals import _not_none, dependencies, docstring, warnings
1818
from .utils import to_rgb, to_xyz
1919

2020
__all__ = [
@@ -841,9 +841,9 @@ def show_fonts(
841841
show_cycles
842842
show_colors
843843
"""
844+
# Select fonts for plotting. Default is to show sans-serif fonts. Otherwise
845+
# fonts can be specified as input arguments or with the family keyword
844846
if not args and family is None:
845-
# User fonts and sans-serif fonts. Note all proplot sans-serif
846-
# fonts are added to 'font.sans-serif' by default
847847
args = sorted(
848848
{
849849
font.name for font in mfonts.fontManager.ttflist
@@ -879,7 +879,7 @@ def show_fonts(
879879
}
880880
)
881881

882-
# Text
882+
# The default sample text
883883
if text is None:
884884
text = (
885885
'the quick brown fox jumps over a lazy dog' '\n'
@@ -893,12 +893,22 @@ def show_fonts(
893893
r'$\Phi\phi$ $\Psi\psi$ $\Omega\omega$ !?&#%'
894894
)
895895

896+
# Settings for rendering math text
897+
ctx = {
898+
'mathtext.default': 'regular',
899+
'mathtext.fontset': 'custom',
900+
}
901+
if dependencies._version_mpl < 3.4:
902+
ctx['mathtext.fallback_to_cm'] = False
903+
else:
904+
ctx['mathtext.fallback'] = None
905+
896906
# Create figure
897907
refheight = 1.2 * (text.count('\n') + 2.5) * size / 72
898908
fig, axs = ui.subplots(
899909
refwidth=4.5, refheight=refheight, nrows=len(args), ncols=1, space=0,
900-
mathtext_fallback=False
901910
)
911+
fig._render_context.update(ctx)
902912
axs.format(
903913
xloc='neither', yloc='neither',
904914
xlocator='null', ylocator='null', alpha=0

proplot/figure.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
_pop_rc,
2727
_translate_loc,
2828
context,
29-
dependencies,
3029
docstring,
3130
texts,
3231
warnings,
@@ -466,7 +465,7 @@ def _canvas_preprocess(self, *args, **kwargs):
466465
# call in this function before proceeding with print_figure).
467466
ctx1 = fig._context_adjusting(cache=(method != 'print_figure'))
468467
ctx2 = fig._context_authorized() # backends might call set_constrained_layout()
469-
ctx3 = rc.context(fig._mathtext_context) # draw with figure-specific setting
468+
ctx3 = rc.context(fig._render_context) # draw with figure-specific setting
470469
with ctx1, ctx2, ctx3:
471470
fig.auto_layout()
472471
return func(self, *args, **kwargs)
@@ -715,7 +714,7 @@ def __init__(
715714
self._is_adjusting = False
716715
self._is_authorized = False
717716
self._includepanels = None
718-
self._mathtext_context = {}
717+
self._render_context = {}
719718
rc_kw, rc_mode = _pop_rc(kwargs)
720719
kw_format = _pop_params(kwargs, self._format_signature)
721720
with self._context_authorized():
@@ -1468,6 +1467,7 @@ def _align_content(): # noqa: E306
14681467
gs._auto_layout_tight(renderer)
14691468
_align_content()
14701469

1470+
@warnings._rename_kwargs('0.10', mathtext_fallback='pplt.rc.mathtext_fallback = {}')
14711471
@docstring._snippet_manager
14721472
def format(
14731473
self, axs=None, *,
@@ -1477,7 +1477,7 @@ def format(
14771477
blabels=None, bottomlabels=None, bottomlabels_kw=None,
14781478
tlabels=None, toplabels=None, toplabels_kw=None,
14791479
rowlabels=None, collabels=None, # aliases
1480-
includepanels=None, mathtext_fallback=None, **kwargs,
1480+
includepanels=None, **kwargs,
14811481
):
14821482
"""
14831483
Modify figure-wide labels and call ``format`` for the
@@ -1523,24 +1523,16 @@ def format(
15231523
kw = rc.fill({'facecolor': 'figure.facecolor'}, context=True)
15241524
self.patch.update(kw)
15251525

1526-
# Update text drawing behavior
1527-
if includepanels is not None:
1528-
self._includepanels = includepanels
1529-
if mathtext_fallback is not None:
1530-
if dependencies._version_mpl >= 3.4:
1531-
context = {'mathtext.fallback': mathtext_fallback if isinstance(mathtext_fallback, str) else 'cm' if mathtext_fallback else None} # noqa: E501
1532-
else:
1533-
context = {'mathtext.fallback_to_cm': bool(mathtext_fallback)}
1534-
self._mathtext_context = context
1535-
1536-
# Update super title and label padding
1526+
# Update super title and label spacing
15371527
pad = rc.find('suptitle.pad', context=True) # super title
15381528
if pad is not None:
15391529
self._suptitle_pad = pad
15401530
for side in tuple(self._suplabel_pad): # super labels
15411531
pad = rc.find(side + 'label.pad', context=True)
15421532
if pad is not None:
15431533
self._suplabel_pad[side] = pad
1534+
if includepanels is not None:
1535+
self._includepanels = includepanels
15441536

15451537
# Update super title and labels text and settings
15461538
suptitle_kw = suptitle_kw or {}

0 commit comments

Comments
 (0)