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.
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 actually solved by
import matplotlib.font_manager
I was facing a similar issue in a Cloud Datalab docker image running on a gcloud VM. Executing the following fixed the issue for me:
$ sudo apt install msttcorefonts -qq
$ rm ~/.cache/matplotlib -rf
Here is instructions on how to get to the docker image running on the gcloud VM containing the Datalab instance just in case.
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:
sudo apt install font-manager
rm ~/.cache/matplotlib -fr
No more error messages about sans-serif.
try all the methods above, not work for me.
my way to solve this is a little dirrent cause I'm using conda on ubuntu server running jupyter
locate -b '\mpl-data'
find a folder
/usr/share/matplotlib/mpl-data
then I add the simhei fonts into the font folder in mpl-data . then remove matplotlib fonts cache
rm -rf ~/.cache/matplotlib
restart jupyter notebook, and it works.
It took me many hours to finally figure out that I needed to update matplotlib.
My original version of 3.0.3
(which came with my jupyter-datascience docker image) would give me this error, but updating to 3.1.1
fixed it.
In the end, my docker script:
RUN pip install matplotlib==3.1.1
COPY fonts /usr/share/fonts/truetype/
RUN fc-cache -fv
RUN rm /home/jovyan/.cache/matplotlib -rf
is what did it for me.