永久解决matplotlib中文乱码问题
永久解决matplotlib中文乱码问题
1. 拷贝Simhei.ttf字体文件至以下目录
/root/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf # 根据自己系统酌情设置
2. 设置matplotlibrc文件
(tensorflow) [root@bigdata ~]# python
>>> import matplotlib
>>> print(matplotlib.matplotlib_fname()) # 设置文件
/root/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc
# 打开文件并设置以下属性,vi编辑器,用/font.family搜索font.famliy位置
font.family : sans-serif
font.sans-serif : Simhei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif # 增加Simhei
axes.unicode_minus : False # 修改为False,作用是解决负号的乱码问题
3. 删除matplotlib缓存
(tensorflow) [root@bigdata ~]# python
>>> import matplotlib
>>> print(matplotlib.get_cachedir()) # 缓存目录
/root/.cache/matplotlib
(tensorflow) [root@bigdata ~]# rm -rf /root/.cache/matplotlib
God will send the rain when you are ready.You need to prepare your field to receive it.