解决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
人就像是被蒙着眼推磨的驴子,生活就像一条鞭子;当鞭子抽到你背上时,你就只能一直往前走,虽然连你也不知道要走到什么时候为止,便一直这么坚持着。