Skip to content

Matplotlib cannot find default matplotlib fonts on Scientific linux #8427

Closed
@mhearne-usgs

Description

@mhearne-usgs

To help us understand and resolve your issue, please fill out the form to the best of your ability. You can feel free to delete the sections that do not apply.

Bug report

Bug summary

Matplotlib cannot seem to find any of its own fonts on my Scientific Linux system - I get all sorts of warnings like "Font family ['STIXNonUnicode'] not found" and "findfont: Could not match :family=DejaVu Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0. Returning /usr/share/fonts/dejavu/DejaVuSansMono-Oblique.ttf".

Code for reproduction

  • A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required
#!/usr/bin/env python

import matplotlib
matplotlib.use('Agg')

from matplotlib import pyplot as plt
import numpy as np


if __name__ == '__main__':
    x = np.linspace(0.0, 5.0, 100)
    y = np.cos(2*np.pi*x) * np.exp(-x)
    
    plt.plot(x, y, 'k')
    plt.title('Damped exponential decay')
    #plt.text(2, 0.65, r'$\cos(2 \pi t) \exp(-t)$', fontname='DejaVu Sans')
    plt.text(2, 0.65, r'$\cos(2 \pi t) \exp(-t)$') 
    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.savefig('output.png')

Actual outcome

  • The output produced by the above code, which may be a screenshot, console output, etc.
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1307: UserWarning: findfont: Could not match :family=DejaVu Sans:style=normal:variant=normal:weight=400:stretch=normal:size=10.0. Returning /usr/share/fonts/dejavu/DejaVuSansMono-Oblique.ttf
  UserWarning)
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXGeneral'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1307: UserWarning: findfont: Could not match :family=DejaVu Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0. Returning /usr/share/fonts/dejavu/DejaVuSansMono-Oblique.ttf
  UserWarning)
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1307: UserWarning: findfont: Could not match :family=DejaVu Sans:style=italic:variant=normal:weight=normal:stretch=normal:size=10.0. Returning /usr/share/fonts/dejavu/DejaVuSansMono-Oblique.ttf
  UserWarning)
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1307: UserWarning: findfont: Could not match :family=DejaVu Sans:style=normal:variant=normal:weight=700:stretch=normal:size=10.0. Returning /usr/share/fonts/dejavu/DejaVuSansMono-Oblique.ttf
  UserWarning)
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXNonUnicode'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXSizeOneSym'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXSizeTwoSym'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXSizeThreeSym'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXSizeFourSym'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['STIXSizeFiveSym'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmsy10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmr10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmtt10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmmi10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmb10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmss10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['cmex10'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['DejaVu Sans Display'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/home/pager/miniconda/envs/pager/lib/python3.6/site-packages/matplotlib/font_manager.py:1307: UserWarning: findfont: Could not match :family=DejaVu Sans:style=normal:variant=normal:weight=400:stretch=normal:size=12.0. Returning /usr/share/fonts/dejavu/DejaVuSansMono-Oblique.ttf
  UserWarning)

Expected outcome
On my Mac, there are no warnings.
Matplotlib version
matplotlib.version => '2.0.0'

Python 3.6.1 | packaged by conda-forge | (default, Mar 23 2017, 21:05:12)

Linux localhost 3.10.0-514.10.2.el7.x86_64 #1 SMP Thu Mar 2 11:21:24 CST 2017 x86_64 x86_64 x86_64 GNU/Linux

Scientific Linux release 7.3 (Nitrogen)

Python and matplotlib were both installed using conda from conda-forge.

Also, I have made NO customizations in any matplotlibrc files, and there are no files under ~/.config/matplotlib.

The actual problem caused by all of this is of course in a much more complicated application, where a map I'm making has the wrong font (italicized, at that) in it when created on Linux.

Incidentally, I could really use a workaround, as I was hoping to deploy some code on Linux this week. Is there a way to tell matplotlib (perhaps in a matplotlibrc file) where to find the true type fonts that are included with the distribution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions