Skip to content

Font/Mathfont and fallbacks buggy #14829

Closed

Description

@andrzejnovak

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

Activity

  1. matthewfeickert commented on Aug 22, 2020

    @matthewfeickert
    Contributor

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

  2. andrzejnovak commented on Aug 23, 2020

    @andrzejnovak
    ContributorAuthor

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

  3. matthewfeickert commented on Aug 23, 2020

    @matthewfeickert
    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?

  4. anntzer commented on Aug 23, 2020

    @anntzer
    Contributor

    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?

  5. andrzejnovak commented on Aug 23, 2020

    @andrzejnovak
    ContributorAuthor

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

  6. anntzer commented on Aug 23, 2020

    @anntzer
    Contributor

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

  7. andrzejnovak commented on Aug 23, 2020

    @andrzejnovak
    ContributorAuthor

    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.

  8. matthewfeickert commented on Oct 30, 2020

    @matthewfeickert
    Contributor

    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).

  9. matthewfeickert commented on Jan 8, 2021

    @matthewfeickert
    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

  10. matthewfeickert commented on Jan 8, 2021

    @matthewfeickert
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions