FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Plotting legend throws error "font family ['serif'] not found. Falling back to DejaVu Sans" · Issue #17518 · matplotlib/matplotlib · GitHub

Repository navigation

Plotting legend throws error "font family ['serif'] not found. Falling back to DejaVu Sans" #17518

Closed

Description

Bug report

Bug summary

Matplotlib shows a warning when adding a legend to a graph while using the TeX backend.
Error is: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.
A typical looking graph is supplied but I'm unsure as to the correctness of the legend font.

Code for reproduction

from matplotlib import rc
import matplotlib.pyplot as plt

rc('font', **{'family':'serif','serif':'Computer Modern'})
rc('text', usetex=True)

plt.figure()
plt.plot(0,0,label='Input')
plt.title('Commenting out legend removes warning')

plt.legend()

plt.show()

Actual outcome

findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.

The graph is output normally.

Expected outcome

No errors, and a key that works.

Matplotlib version

  • Operating system: Ubuntu Focal Fossa GNOME Terminal 3.36.1.1
  • Matplotlib version: 3.2.1
  • Matplotlib backend (print(matplotlib.get_backend())): GTK3Agg
  • Python version: 3.8.2 (GCC 9.3.0 on linux)
  • Jupyter version (if applicable): NA
  • Other libraries:

matplotlib was installed via pip (20.1.1), and python was installed via apt.

Activity

  1. jklymak commented on May 27, 2020

    Member

    I get this as well, but I assume thats because I don't have computer modern installed where find font can find it. If I change to "Palatino" or "DejaVu Sans" everything works fine.

    https://matplotlib.org/3.1.1/tutorials/text/usetex.html could be improved with a bit more description of how to install the fonts.

    The error message could probably be improved. @anntzer, is it possible for the error message to specify the font names tried? ie. this would have been less mysterious to me if it had said:

    findfont: No fonts in family 'serif' ['Computer Modern', 'Other fonts in list'] were found. Falling back to DejaVu Sans.

    Finally, why is the warning only triggered for legend? It applies to the other text elements as well. having it only apply to legend (or I assume text) makes it mysterious!

  2. added this to the v3.4.0 milestone on May 27, 2020
  3. Struan-Murray commented on May 27, 2020

    ContributorAuthor

    (or I assume text)

    plt.text(0, 0, 'Text test')

    Not even text throws a warning, I've only managed to find it throw the warning on legend so far.

  4. anntzer commented on May 27, 2020

    Contributor

    Looks like the fix is

    diff --git i/lib/matplotlib/offsetbox.py w/lib/matplotlib/offsetbox.py
    index 19fceb313..896bc6281 100644
    --- i/lib/matplotlib/offsetbox.py
    +++ w/lib/matplotlib/offsetbox.py
    @@ -876,7 +876,8 @@ class TextArea(OffsetBox):
     
         def get_extent(self, renderer):
             _, h_, d_ = renderer.get_text_width_height_descent(
    -            "lp", self._text._fontproperties, ismath=False)
    +            "lp", self._text._fontproperties,
    +            ismath="TeX" if self._text.get_usetex() else False)
     
             bbox, info, d = self._text._get_layout(renderer)
             w, h = bbox.width, bbox.height

    As usual, brownie points for whoever turns this into a PR.

  5. jklymak commented on May 27, 2020

    Member

    Is that snippet used everywhere else? Maybe get_text_width_height_descent needs to be changed?

  6. anntzer commented on May 27, 2020

    Contributor

    A quick grep suggests the only other relevant place is contour, but that's handled in #16171.

  7. Struan-Murray commented on May 27, 2020

    ContributorAuthor

    Never done a pull request before but I'll give it a go.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL