jupyter-notebook in question is not supported by the Chinese matplotlib (Linux)

Introduction:
the problem is not a screenshot, jupyter-notebook using plt drawn image, Chinese are small squares (garbled)
solution is as follows

1. Linux install fonts

The Windows font C:/Windows/Fontscopy the font path to store the Linux system /usr/share/fonts, the Figure:

cd to /usr/share/fonts/Fonts, that is, to copy the folder, create font index information, updates the font cache, so that font into effect, run the command:
mkfontscale && mkfontdir && fc-cache -fv && source /etc/profile && fc-list |wc -l

View fontsfc-list :lang=zh

2. Add Configuration

There are many versions, such as:

import matplotlib
matplotlib.use('qt4agg')
#指定默认字体
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family']='sans-serif' #解决负号'-'显示为方块的问题
matplotlib.rcParams['axes.unicode_minus'] = False

My setup is:

from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['STSong']
mpl.rcParams['axes.unicode_minus'] = False

As shown, may show the normal Chinese

3. If not enough, clear the cache

If the second part of the configuration is added, but still display Chinese garbled, then there may be problems cache, executionrm -r ~/.cache/matplotlib

Guess you like

Origin www.cnblogs.com/geoffreyone/p/10950790.html