question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matplotlib warning about no LaTeX-compatible font.

See original GitHub issue

Hi,

Whenever I use this package setting

plt.style.use(["science"])
plt.style.reload_library()

I get the following warning sign multiple times when I plot anything:

matplotlib.texmanager - INFO - No LaTeX-compatible font found for the serif font family in rcParams. Using default.

Now, I have investigated a little, this warning is issued here:

https://github.com/matplotlib/matplotlib/blob/02af61b3000b93efad98f415b4a7eb330c9e46c1/lib/matplotlib/texmanager.py#L124

so it looks like it cannot found the specified font in the attribute TexManager.font_info. I have printed the font that is trying to look at, and it is “Times New Roman”, as you would expect, but indeed that font is not found in the font_info dictionary:

https://github.com/matplotlib/matplotlib/blob/02af61b3000b93efad98f415b4a7eb330c9e46c1/lib/matplotlib/texmanager.py#L62

What am I missing here? I am using:

SciencePlots: latest commite release Matplotlib: 3.3.0 OS: Manjaro 20.2 Tex: Texlive installation with these packages:

texlive-bibtexextra
texlive-core
texlive-fontsextra
texlive-formatsextra
texlive-games
texlive-humanities
texlive-latexextra
texlive-music
texlive-pictures
texlive-pstricks
texlive-publishers
texlive-science

Thank you very much for your help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
Hsinscommented, Nov 19, 2020

Hi @arnauqb

You got that warning because the given font Times New Roman in science style can’t be found in your matplotlib cache. The Times New Roman is a font licensed to Microsoft from Monotype so you can’t find that font in your machine which runs with Linux operating system.


There are two steps to solve your problem:

  1. Install the Times New Roman fonts on your system.

    There are two packages ttf-times-new-roman and ttf-ms-fonts in AUR (Arch User Repository) and you can install one of them by the package manager yay or yaourt in your Manjaro system.

    # Install Times New Roman Fonts with Package Manager
    $ yay -S ttf-times-new-roman     # Option 1
    $ yay -S ttf-ms-fonts            # Option 2
    
    # Clear and Regenerate Your Font Cache (System Fonts Cache)
    $ sudo fc-cache -f -v
    
  2. Then clear the font cache of matplotlib.

    After installing those fonts and regenerate the cache, you can directly use them in software like PyCharm or LibreOffice but still get that warning in matplotlib. You should find out the path of the font cache of matplotlib and clear it.

    If you don’t know the path of the font cache of matplotlib. Just type python in your terminal and run the commands below in the interactive Python REPL environment.

    >>> import matplotlib as plt
    >>> plt.get_cachedir()
    '/home/hsins/.cache/matplotlib'
    

    Then clear the font cache of matplotlib by deleting that folder. (The cache would be regenerated when you run matplotlib next time)

    # Clear the Font Cache of Matplotlib (MUST REPLACE THE PATH TO WHAT YOU GOT IN PREVIOUS STEP)
    $ rm -rf /home/hsins/.cache/matplotlib
    
1reaction
Hsinscommented, Dec 2, 2020

Hi @arnauqb

In commit 86e369f, @garrettj403 have changed the font from Times New Roman to Times. If you use the newest version of SciencePlot in your machine, then it would give warnings if there is no Times font.

Would you show that warning message?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matplotlib not using latex font while text.usetex==True
I want to create labels to my plots with the latex computer modern font. However, the only way to persuade matplotlib to use...
Read more >
texmanager.py:137 - matplotlib-devel - Matplotlib
Hi all, Is there a way to suppress the warning /usr/local/lib64/python2.5/site-packages/matplotlib/texmanager.py:137: UserWarning: No LaTeX-compatible font ...
Read more >
Legend guide — Matplotlib 3.6.2 documentation
The text which describes the handle represented by the key. ... Calling legend() with no arguments automatically fetches the legend handles and their ......
Read more >
matplotlib.collections — Matplotlib 3.6.2 documentation
Rasterized drawing is not supported by all artists. If you try to enable this on an artist that does not support it, the...
Read more >
GitLab Flavored Markdown (GLFM)
When you enter text in the GitLab UI, GitLab assumes the text is in the Markdown language. The text is rendered with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found