Make matplotlib able to display Chinese fonts


Juypter Notebook in Docker container
System: Debian
Python: 3.6

Step 1

Download font file:

And store in the following path:

Stpe 2

Modify the configuration file:

sudo vim /opt/conda/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc

Remove the # infront of and font.sans-serif.

Add Microsoft YaHei at the line of font.sans-serif.

Stpe 3

Remove the cache file of matplotlib:
rm ~/.cache/matplotlib/fontList.py3k.cache

Final Step

Restart python, or close and reopen notebook


If not working on Ubuntu, try to copy the ttf file to /usr/share/fonts