I am using matplotlib version 2.0.0 on Python 3 in a miniconda virtual environment. I am working on a unix scientific computing cluster where I don\'t have root privileges.
There is a conda package for it[1].
So, you don't really need sudo
to fix this!
conda install -c conda-forge -y mscorefonts
restart jupyter and/or force rebuild matplotlib font cache
import matplotlib
matplotlib.font_manager._rebuild()
[1] - https://anaconda.org/conda-forge/mscorefonts
I am in macOS with jupyter notebook, I solved with the following, first close your jupyter notebook. Then find out the font path by doing the following in Python
import matplotlib
print(matplotlib.matplotlib_fname())
it prints /Users/zyy/anaconda2/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
for me, notice matplotlibrc
is a file, not a directory.
Then download font SimHei, and copy it to the directory fonts/ttf
under the mpl-data/
directory above.
Delete directory ~/.cache/matplotlib
and restart your jupyter notebook, everything should be good.
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 toC:\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.
This work for me::
$ sudo apt-get install msttcorefonts -qq