解决matplotlib图中的中文显示方框

1、复制字体到系统目录:sudo cp winfonts/simhei.ttf /usr/share/fonts/TTF/

2、复制字体到matplotlib的字体目录中:sudo cp winfonts/simhei.ttf /usr/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/ttf/

3、修改配置文件:sudo vim /usr/lib/python3.10/site-packages/matplotlib/mpl-data/matplotlibrc,将simhei信息添加,具体就是:

  

1 font.family: simhei, sans-serif
2 #font.style:   normal
3 #font.variant: normal
4 #font.weight:  normal
5 #font.stretch: normal
6 font.size:    14.0
7 
8 font.serif:  simhei, DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
9 font.sans-serif: simhei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

分别在第1、8、9行添加字体信息

4、python WORKM/pythonCode/chapter15/mplSquares.py结果:

终于好了,接着,再看下一章随意长相的猫吧。

 感谢:https://zhuanlan.zhihu.com/p/52779214

posted @ 2022-09-25 17:41  叕叒双又  阅读(405)  评论(0编辑  收藏  举报