Skip to content

Matplotlib not able to find basic fonts #17585

Closed

Description

Bug report

Bug summary

Matplotlib is not able to load fonts.
I have tried to delete the cache following all possible procedures listed in #13139 , as for example removing ~/.cache/matplotlib/fontlist-v310.json , but none of them turned out succesfully. No idea of how to solve this.

Code for reproduction

from matplotlib import rcParams
import matplotlib.font_manager

rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Tahoma']
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], label='test')

#ax.legend(fontsize=22)
plt.show()

Actual outcome

davide@hammer:~/Desktop/Fottiti$ python3 plot.py
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.

[plot is shown but the font is not the required one]

Matplotlib version

  • Operating system: Ubuntu 20.04
  • Matplotlib version: 3.2.1 installed from pip
  • Matplotlib backend (print(matplotlib.get_backend())): GTK3Agg
  • Python version: 3.8.2

Activity

  1. anntzer commented on Jun 6, 2020

    @anntzer
    Contributor

    Please indicate where Tahoma is installed in your system.

  2. local-minimum commented on Jul 2, 2020

    @local-minimum

    I'm having the same issue after upgrading code to Python 3.8.2 / mpl v.3.2.1 running in an Ubuntu 20.04 docker image trying to use Utopia font.

    I installed the utopia font via texlive so locations are:

    /usr/share/texlive/texmf-dist/tex/latex/psnfss/utopia.sty
    /usr/share/texlive/texmf-dist/fonts/afm/adobe/utopia
    /usr/share/texlive/texmf-dist/fonts/tfm/adobe/utopia
    /usr/share/texlive/texmf-dist/fonts/type1/adobe/utopia
    /usr/share/texlive/texmf-dist/fonts/vf/adobe/utopia
    /usr/share/texlive/texmf-dist/fonts/map/dvips/psnfss/utopia.map
    

    This didn't produce warnings before upgrade of ubuntu and python.

    >>> from matplotlib import rc
    >>> from matplotlib import pyplot as plt
    >>> rc('font', **{'family': 'serif', 'serif': ['Utopia']})
    >>> fig = plt.figure(None, (20, 20), 120)
    >>> ax = fig.gca()
    >>> ax.set_xlabel('test')
    Text(0.5, 0, 'test')
    >>> fig.savefig('/tmp/test2.png')
    findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.
    
  3. tacaswell commented on Jul 2, 2020

    @tacaswell
    Member

    @local-minimum in what version did it used to work?

    Can you removing everything in ~/.cache/matplotlib?

  4. QuLogic commented on Jul 2, 2020

    @QuLogic
    Member

    Those paths are for LaTeX; they are not standard paths in which fonts would be found.

  5. anntzer commented on Jul 2, 2020

    @anntzer
    Contributor

    There's no real reason why we shouldn't also query them (especially if that's something that can be somewhat automated with e.g. kpsewhich). However the real problem is that these are Type1 (pfb) fonts, which we don't support (well, we support them for raster/png output but not for vector output because of the reliance on ttconv) and therefore it makes sense not to have them (for now) in the cache. To be revisited once ttconv is a thing of the past :)

  6. local-minimum commented on Jul 3, 2020

    @local-minimum

    Thanks for the clarification, might or might not be related to the OP though, but for me, I agree that it makes sense and I guess something changed with ubuntu and what fonts are included how.

  7. sesise0307 commented on Aug 18, 2020

    @sesise0307

    @local-minimum in what version did it used to work?

    Can you removing everything in ~/.cache/matplotlib?

    It helped me. Thanks!

  8. jklymak commented on Sep 7, 2020

    @jklymak
    Member

    This looks to be resolved for the responsive commenters. If there is still an issue we can re-open if more info is provided...

  9. matthewfeickert commented on Jan 8, 2021

    @matthewfeickert
    Contributor

    Can you removing everything in ~/.cache/matplotlib?

    Removing the full cache has proven to be very helpful (for me) for debugging things like this. Is there a way to clean the full cache using the matplotlib API similar to how

    import matplotlib.font_manager
    matplotlib.font_manager._rebuild()

    rebuilds the full font-list cache at ~/.cache/matplotlib/fontlist-v330.json?

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