Matplotlib cannot find basic fonts
To get it to work, I had to combine the two current top answers. Here's what worked for me:
$ sudo apt install msttcorefonts -qq
$ rm ~/.cache/matplotlib -rf
I had this exact same problem on a Vagrant VM running Ubuntu Xenial 64-bit. No matter how many fonts I had already installed, matplotlib was having a problem with the "system" font name "sans-serif". I fixed it by:
- Stopping Jupyter
- Installing font-manager:
sudo apt install font-manager
- Cleaning the matplotlib cache directory:
rm ~/.cache/matplotlib -fr
- Restarting Jupyter.
No more error messages about sans-serif.
This work for me::
$ sudo apt-get install msttcorefonts -qq
A solution for Windows users, when confronted with the warning:
UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
Delete the fonts located in matplotlib's cache.
Cache's location:import matplotlib as mpl; print(mpl.font_manager.get_cachedir())
Find matplotlib's font directory. The path might be similar to
C:\Miniconda3\pkgs\matplotlib-2.2.2-py36_1\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
Copy necessary fonts like Computer Modern to this directory.
The warning may persist, but your plots' font should change appropriately.
I actually solved by
import matplotlib.font_manager