-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
\times in minor ticklabels not recognized due to \mathdefault #10029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
May I please bump this? More than 3 years down the line, this is still a problem in Matplotlib 3.4.1. |
Seems reasonable. Did you have a fix? |
My guess is that the solution would be similar to #17007 (comment) / #18397. |
@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 |
@aitikgupta Perhaps this and the issues linked in my previous message may be of interest for you. |
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:
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):
|
This is still not fixed on the current |
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. |
Is it worth considering the short-term fix, then? Since this bug is quite old. |
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. |
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 ? |
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. |
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?
This throws
and fails to render minus signs on the horizontal axis. (Setting So I believe the warning is genuine and should not be removed? |
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. |
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
Actual outcome
Expected outcome

This is only a problem with matplotlib 2.x, as 1.x never automatically places minor ticklabels.
Matplotlib version
I have installed Python and matplotlib from source.
The text was updated successfully, but these errors were encountered: