matplotlib用着用着出问题了…哎呀
问题如下:
findfont: Font family [‘sans-serif’] not found. Falling back to DejaVu Sans.
findfont: Generic family ‘sans-serif’ not found because none of the following families were found: SimHei
ValueError: Failed to find font DejaVu Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0, and fallback to the default font was disabled
解决办法:
1.在Windows系统C盘中搜索得到一个文件名叫simhei.ttf的简体字字体文件。注意有些从网上下载的simhei.ttf并不能解决问题(已经试过了)。
2.放到E:\Anaconda3.8\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
文件下,并重命名为SimHei.ttf。
3.打开目录E:\Anaconda3.8\Lib\site-packages\matplotlib\mpl-data
下的matplotlibrc
文件
4. 修改matplotlibrc
文件。这个网上有很多可以参考。
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
# 去掉前面的#,并将True改为False
5.问题解决了。