Skip to content

Commit

Permalink
Remove mathtext_fallback figure keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelbd committed Jan 14, 2022
1 parent f2b16b5 commit 5ce23a5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
24 changes: 14 additions & 10 deletions docs/fonts.py
Expand Up @@ -67,19 +67,23 @@
# :ref:`default proplotrc file <ug_proplotrc>`.
#
# To compare different fonts, use the `~proplot.demos.show_fonts` command with the
# `family` keyword (default behavior is ``family='sans-serif'``). Tables of the
# TeX Gyre and sans-serif fonts packaged with proplot are shown below. The "陇" symbol
# appears where characters for a particular font are unavailable (when making plots,
# "陇" is replaced with the character from a fallback font). Since most TeX Gyre fonts
# have limited character sets, if your plots contain lots of mathematical symbols,
# you may want to set :rcraw:`font.family` to the matplotlib-packaged
# font ``'DejaVu Sans'`` or the proplot-packaged font ``'Fira Math'``
# (see `this page <https://github.com/firamath/firamath>`__ for more on Fira Math).
# `family` keyword (default behavior is ``family='sans-serif'``). Tables of the TeX
# Gyre and sans-serif fonts packaged with proplot are shown below. In order to show how
# the fonts perform as math text, the demo is rendered with :rcraw:`mathtext.default`
# = ``'regular'``, :rcraw:`mathtext.fontset` = ``'custom'``, and
# :rcraw:`mathtext.fallback` = ``None``. This uses the global :rcraw:`font.family`
# for the math text and shows a dummy glyph "陇" is shown where math characters
# are unavailable (see the matplotlib `math text guide
# <https://matplotlib.org/stable/tutorials/text/mathtext.html#custom-fonts>`__
# for details). In practice, proplot uses a standard non-italicized math
# text everywhere by setting :rc:`mathtext.fontset` = ``'stixsans'`` and
# :rcraw:`mathtext.default = 'rm'` (see the :ref:`proplotrc file <ug_proplotrc>`
# for details).
#
# .. note::
#
# Try to avoid ``.ttf`` files with ``Thin`` in the file name. Some versions of
# matplotlib interpret fonts with the "thin" style as having *normal* weight (see
# Try to avoid "thin" ``.ttf`` files. Some versions of matplotlib
# interpret fonts with the "thin" style as having *normal* weight (see
# `this issue page <https://github.com/matplotlib/matplotlib/issues/8788>`__),
# causing them to override the correct normal weight versions. While proplot
# tries to filter out these files, this cannot be done systematically. In the
Expand Down
6 changes: 0 additions & 6 deletions proplot/axes/base.py
Expand Up @@ -387,12 +387,6 @@
Whether to include panels when aligning figure "super titles" along the top
of the subplot grid and when aligning the `spanx` *x* axis labels and
`spany` *y* axis labels along the sides of the subplot grid.
mathtext_fallback : bool or str, default: :rc:`mathtext.fallback`
Apply this :rcraw:`mathtext.fallback` value when drawing the figure. If
``True`` or string, unavailable glyphs are replaced with a glyph from a
fallback font (Computer Modern by default). Otherwise, they are replaced
with the "陇" dummy character. For details see this `mathtext tutorial \
<https://matplotlib.org/stable/tutorials/text/mathtext.html#custom-fonts>`__.
"""
_rc_init_docstring = """
"""
Expand Down
20 changes: 15 additions & 5 deletions proplot/demos.py
Expand Up @@ -14,7 +14,7 @@
from . import constructor, ui
from .config import _get_data_folders, rc
from .internals import ic # noqa: F401
from .internals import _not_none, docstring, warnings
from .internals import _not_none, dependencies, docstring, warnings
from .utils import to_rgb, to_xyz

__all__ = [
Expand Down Expand Up @@ -841,9 +841,9 @@ def show_fonts(
show_cycles
show_colors
"""
# Select fonts for plotting. Default is to show sans-serif fonts. Otherwise
# fonts can be specified as input arguments or with the family keyword
if not args and family is None:
# User fonts and sans-serif fonts. Note all proplot sans-serif
# fonts are added to 'font.sans-serif' by default
args = sorted(
{
font.name for font in mfonts.fontManager.ttflist
Expand Down Expand Up @@ -879,7 +879,7 @@ def show_fonts(
}
)

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

# Settings for rendering math text
ctx = {
'mathtext.default': 'regular',
'mathtext.fontset': 'custom',
}
if dependencies._version_mpl < 3.4:
ctx['mathtext.fallback_to_cm'] = False
else:
ctx['mathtext.fallback'] = None

# Create figure
refheight = 1.2 * (text.count('\n') + 2.5) * size / 72
fig, axs = ui.subplots(
refwidth=4.5, refheight=refheight, nrows=len(args), ncols=1, space=0,
mathtext_fallback=False
)
fig._render_context.update(ctx)
axs.format(
xloc='neither', yloc='neither',
xlocator='null', ylocator='null', alpha=0
Expand Down
22 changes: 7 additions & 15 deletions proplot/figure.py
Expand Up @@ -26,7 +26,6 @@
_pop_rc,
_translate_loc,
context,
dependencies,
docstring,
texts,
warnings,
Expand Down Expand Up @@ -466,7 +465,7 @@ def _canvas_preprocess(self, *args, **kwargs):
# call in this function before proceeding with print_figure).
ctx1 = fig._context_adjusting(cache=(method != 'print_figure'))
ctx2 = fig._context_authorized() # backends might call set_constrained_layout()
ctx3 = rc.context(fig._mathtext_context) # draw with figure-specific setting
ctx3 = rc.context(fig._render_context) # draw with figure-specific setting
with ctx1, ctx2, ctx3:
fig.auto_layout()
return func(self, *args, **kwargs)
Expand Down Expand Up @@ -715,7 +714,7 @@ def __init__(
self._is_adjusting = False
self._is_authorized = False
self._includepanels = None
self._mathtext_context = {}
self._render_context = {}
rc_kw, rc_mode = _pop_rc(kwargs)
kw_format = _pop_params(kwargs, self._format_signature)
with self._context_authorized():
Expand Down Expand Up @@ -1468,6 +1467,7 @@ def _align_content(): # noqa: E306
gs._auto_layout_tight(renderer)
_align_content()

@warnings._rename_kwargs('0.10', mathtext_fallback='pplt.rc.mathtext_fallback = {}')
@docstring._snippet_manager
def format(
self, axs=None, *,
Expand All @@ -1477,7 +1477,7 @@ def format(
blabels=None, bottomlabels=None, bottomlabels_kw=None,
tlabels=None, toplabels=None, toplabels_kw=None,
rowlabels=None, collabels=None, # aliases
includepanels=None, mathtext_fallback=None, **kwargs,
includepanels=None, **kwargs,
):
"""
Modify figure-wide labels and call ``format`` for the
Expand Down Expand Up @@ -1523,24 +1523,16 @@ def format(
kw = rc.fill({'facecolor': 'figure.facecolor'}, context=True)
self.patch.update(kw)

# Update text drawing behavior
if includepanels is not None:
self._includepanels = includepanels
if mathtext_fallback is not None:
if dependencies._version_mpl >= 3.4:
context = {'mathtext.fallback': mathtext_fallback if isinstance(mathtext_fallback, str) else 'cm' if mathtext_fallback else None} # noqa: E501
else:
context = {'mathtext.fallback_to_cm': bool(mathtext_fallback)}
self._mathtext_context = context

# Update super title and label padding
# Update super title and label spacing
pad = rc.find('suptitle.pad', context=True) # super title
if pad is not None:
self._suptitle_pad = pad
for side in tuple(self._suplabel_pad): # super labels
pad = rc.find(side + 'label.pad', context=True)
if pad is not None:
self._suplabel_pad[side] = pad
if includepanels is not None:
self._includepanels = includepanels

# Update super title and labels text and settings
suptitle_kw = suptitle_kw or {}
Expand Down

0 comments on commit 5ce23a5

Please sign in to comment.