Skip to content
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

Font/Mathfont and fallbacks buggy #14829

Closed
andrzejnovak opened this issue Jul 17, 2019 · 10 comments
Closed

Font/Mathfont and fallbacks buggy #14829

andrzejnovak opened this issue Jul 17, 2019 · 10 comments

Comments

@andrzejnovak
Copy link
Contributor

andrzejnovak commented Jul 17, 2019

Bug report

Bug summary

Strange behaviour when trying to use non default fonts. Namely Arial.

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams.update({'font.sans-serif': "Arial",
                     'font.family': "sans-serif",
                     'font.size' : 30,                   
                    })
f,ax = plt.subplots()
x = np.linspace(0,10,101)
y = x**(2)
ax.plot(x,y)
ax.semilogy()
f.show()

gives Font 'default' does not have a glyph for '-' [U+2212], substituting with a dummy symbol.
and doesn't render right, fair enough.
image

Trying to fix it by setting mathtext, even though I would not expect it to have an effect since the font of the axis does change just by specifying 'font.sans-serif': "Arial"

plt.rcParams.update({'font.sans-serif': "Arial",
                     'font.family': "sans-serif",
                     'font.size' : 30,
                     'mathtext.fontset' : 'custom',
                     'mathtext.rm' : 'Arial',                     
                    })

Instead leads to - being replaced from cm:

findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans.
Substituting with a symbol from Computer Modern.

image

This seems to be inconsistent because it looks like when 'mathtext.fontset'' : 'custom', regular font will fall back to math font which will the fall back to CM. If not changed, it does not fall back. It would be nice instead to be able to specify the fallback font manually.

**

Matplotlib version

  • Matplotlib version: 3.1.0
  • Matplotlib backend (module://ipykernel.pylab.backend_inline):
  • Python version: 3.7.3 (conda)
  • Jupyter version (if applicable): 1.0.0
@matthewfeickert
Copy link
Contributor

@anntzer As you triaged this, can you comment on if there is any new information on this? Or if you have general thoughts?

@andrzejnovak
Copy link
Contributor Author

andrzejnovak commented Aug 23, 2020

Hmm #16509 should have closed this I think, or it could stay as a reminder to add the discussed font list for mathtext

@matthewfeickert
Copy link
Contributor

Hmm #16509 should have closed this I think

As discussed in scikit-hep/mplhep#178 (comment) I'm still seeing this on Ubuntu 19.10, but not on Debian buster. So this is a fonts issue on the user side.

it could stay as a reminder to add the discussed font list for mathtext

So perhaps this is the best for the time being?

@anntzer
Copy link
Contributor

anntzer commented Aug 23, 2020

I have nothing to add for now, I guess I'd need to try to repro the original bug report to know more but... not now :)

Edit: I can't repro the issue here locally, and from the mplhep repo it's not clear either how to repro (without access to the specific distro), so I guess I'll close this for now as not actionable on our side, but feel free to request a reopen if you figure out if there's a font setup that easily reproes this?

@anntzer anntzer closed this as completed Aug 23, 2020
@andrzejnovak
Copy link
Contributor Author

@anntzer this was largely fixed in #16509 and is not related to the mplhep issue

@anntzer
Copy link
Contributor

anntzer commented Aug 23, 2020

So you agree this can be closed? Or did I miss anything?

@andrzejnovak
Copy link
Contributor Author

Yeah, sorry. Should open a new issue to have a fallback lists for mathtext like for regular fonts. I still think that would be useful, but imo is low prio.

@matthewfeickert
Copy link
Contributor

matthewfeickert commented Oct 30, 2020

So this is a fonts issue on the user side.

For the record, the fix was incredibly easy and just total oversight on my part. I had forgotten that matplotlib has a font cache and matplotlib.font_manager. So all that is needed is

import matplotlib.font_manager
matplotlib.font_manager._rebuild()

as I apparently had the correct fonts (I think all that is needed is the dejavu font).

@matthewfeickert
Copy link
Contributor

I ran into this again on Ubuntu 20.04 and I am unable to solve this like I did previously, so I made the following Stack Overflow question: matplotlib mathtext font warning: Font 'default' does not have a glyph

@matthewfeickert
Copy link
Contributor

I ran into this again on Ubuntu 20.04 and I am unable to solve this like I did previously, so I made the following Stack Overflow question: matplotlib mathtext font warning: Font 'default' does not have a glyph

For this Stack Overflow question the fix ended up being more subtle than just the font list cache, as I had more than just fontlist-v330.json in the matplotlib cache

$ ls -htra ~/.cache/matplotlib/
..  tex.cache  fontlist-v330.json  .

so rebuilding the font list cache with

import matplotlib.font_manager
matplotlib.font_manager._rebuild()

or

rm ~/.cache/matplotlib/fontlist-v330.json

wasn't sufficient. Instead the entire matplotlib cache needs to be updated, which is most easily done with

rm ~/.cache/matplotlib/*

I'm not sure if there is a way from the matplotlib API to clean and rebuild the entire cache though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants