FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

\times in minor ticklabels not recognized due to \mathdefault · Issue #10029 · matplotlib/matplotlib · GitHub

Repository navigation

\times in minor ticklabels not recognized due to \mathdefault #10029

Closed

Description

Bug report

Bug summary
The '\times' glyph in minor ticklabels of log plots is not being recognized because it is getting wrapped inside '\mathdefault{...}'. The problem and a temporary solution (simply removing '\mathdefault') is fully described on Stack Overflow.

Code for reproduction

import matplotlib
import matplotlib.pyplot as plt

# Customize matplotlib
matplotlib.rcParams.update({# Use mathtext, not LaTeX
                            'text.usetex': False,
                            # Use the Computer modern font
                            'font.family': 'serif',
                            'font.serif': 'cmr10',
                            'mathtext.fontset': 'cm',
                            # Use ASCII minus
                            'axes.unicode_minus': False,
                            })

# Plot
plt.semilogy([-0.03, 0.05], [0.3, 0.05])
plt.savefig('test.png')

Actual outcome

python/lib/python3.6/site-packages/matplotlib/mathtext.py:866: MathTextWarning: Font 'default' does not have a glyph for '\times' [U+d7]
  MathTextWarning)
python/lib/python3.6/site-packages/matplotlib/mathtext.py:867: MathTextWarning: Substituting with a dummy symbol.
  warn("Substituting with a dummy symbol.", MathTextWarning)

Expected outcome

This is only a problem with matplotlib 2.x, as 1.x never automatically places minor ticklabels.

Matplotlib version

  • Operating system: Linux
  • Matplotlib version: 2.0.2, but the bug is consistently reproduced in all of matplotlib 2.x
  • Matplotlib backend: Agg, TkAgg
  • Python version: 3.6

I have installed Python and matplotlib from source.

Activity

  1. jmd-dk commented on Apr 14, 2021

    Author

    May I please bump this? More than 3 years down the line, this is still a problem in Matplotlib 3.4.1.

  2. jklymak commented on Apr 14, 2021

    Member

    Seems reasonable. Did you have a fix?

  3. anntzer commented on Apr 14, 2021

    Contributor

    My guess is that the solution would be similar to #17007 (comment) / #18397.

  4. jmd-dk commented on Apr 14, 2021

    Author

    @jklymak Not an actual one. I have an ugly workaround, as demonstrated on StackOverflow (see link above). Reading my answer there, the underlying problem should be apparent. I think it won't be hard to fix for one with knowledge of the matpltolib.mathtext internals.

  5. anntzer commented on Apr 14, 2021

    Contributor

    @aitikgupta Perhaps this and the issues linked in my previous message may be of interest for you.

  6. aitikgupta commented on Apr 15, 2021

    Contributor

    A simple fix would be what @anntzer mentioned, i.e. similar to #18397

    A long term fix would be define fallback for mathtext such that the process of finding symbols:

    where symbols (e.g. minus) and letters/digits are in different font files (cmr10/cmsy10);

    would be automated. I can take this up during the GSoC period once the fallback for non-mathtext is implemented, for now I guess it'd be better to go with the simple fix.

    Or an even longer term fix would again be what @anntzer mentioned in #17007 (comment):

    Long term I would like to get rid of the numerous cmXX10 fonts and replace them by the monolithic Latin Modern Math font, which should avoid all these problems.

  7. tfpf commented on Aug 15, 2022

    Contributor

    This is still not fixed on the current main branch. Is there any progress on the long-term fix?

  8. oscargus commented on Aug 15, 2022

    Member

    It is since a few days possible to use font fallback, i.e., when a glyph is not found in the requested font, the next font in the list is tried.

    I guess that there should be a solution using this, but based on my tests (and not really knowing much about the currently introduced change), it may be that this is not implemented for mathtext.

  9. tfpf commented on Aug 16, 2022

    Contributor

    Is it worth considering the short-term fix, then? Since this bug is quite old.

  10. anntzer commented on Aug 18, 2022

    Contributor

    The following basically implements #10029 (comment), I think:

    diff --git i/lib/matplotlib/_mathtext.py w/lib/matplotlib/_mathtext.py
    index 0aa7bec574..53c2eac216 100644
    --- i/lib/matplotlib/_mathtext.py
    +++ w/lib/matplotlib/_mathtext.py
    @@ -462,11 +462,15 @@ class UnicodeFonts(TruetypeFonts):
                 found_symbol = False
                 font = self._get_font(new_fontname)
                 if font is not None:
    -                if font.family_name == "cmr10" and uniindex == 0x2212:
    -                    # minus sign exists in cmsy10 (not cmr10)
    -                    font = get_font(
    -                        cbook._get_data_path("fonts/ttf/cmsy10.ttf"))
    -                    uniindex = 0xa1
    +                if font.family_name == "cmr10":
    +                    if uniindex == 0xd7:  # times sign from cmsy10, not cmr10
    +                        font = get_font(
    +                            cbook._get_data_path("fonts/ttf/cmsy10.ttf"))
    +                        uniindex = 0xa3
    +                    if uniindex == 0x2212:  # minus sign from cmsy10, not cmr10
    +                        font = get_font(
    +                            cbook._get_data_path("fonts/ttf/cmsy10.ttf"))
    +                        uniindex = 0xa1
                     glyphindex = font.get_char_index(uniindex)
                     if glyphindex != 0:
                         found_symbol = True

    #20235 should also be reverted with that patch.

  11. oscargus commented on Aug 18, 2022

    Member

    Discussing this at the dev call today, it seems like implementing font fallback for mathtext is not really feasible. So something like the patch above is the way to go. Are you interested in picking this up @tfpf ?

  12. tfpf commented on Aug 20, 2022

    Contributor

    Sure, will do.

    #20235 should also be reverted with that patch.

    If I understand correctly, this is necessary because font fallback in regular text was implemented by #20740? (I think that should be a separate pull request, though?)

  13. anntzer commented on Aug 20, 2022

    Contributor

    This is unrelated to regular font fallback. mathtext has "always" supported font fallback using its own code (because it was necessary from the very beginning), but a large amount of complexity is that the font files we use for math have irregular encodings that basically need to be hardcoded.

  14. tfpf commented on Aug 21, 2022

    Contributor

    It is still not completely clear to me why it should be reverted.:sweat_smile: If minus signs are not present in that font, and are being substituted in as a result of Mathtext's fallback, it looks like that warning is required?

    import matplotlib.pyplot as plt
    plt.rcdefaults()
    plt.rc('font', family=['cmr10'])
    plt.rc('mathtext', fontset='cm')
    plt.rc('axes.formatter', use_mathtext=False)
    plt.semilogy([-0.03, 0.05], [0.3, 0.05])
    plt.show()
    

    This throws

    UserWarning: cmr10 font should ideally be used with mathtext, set axes.formatter.use_mathtext to True
    UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from current font.
    

    and fails to render minus signs on the horizontal axis. (Setting use_mathtext to True enables the Mathtext fallback for minus signs; setting family to ['cmr10', 'STIXGeneral'] triggers regular font fallback. Either of these two actions results in the minus signs being rendered correctly.)

    So I believe the warning is genuine and should not be removed?

  15. anntzer commented on Aug 21, 2022

    Contributor

    I guess it's no big deal either way, the warning can also be left until we actually switch to a full latin modern font with all glyphs in a single font file.

  16. added this to the v3.7.0 milestone on Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL