解决方式一:修改配置文件
(1)找到matplotlibrc文件(搜索一下就可以找到了)
(2)修改:font.serif和font.sans-serif,我的在205,206行
font.serif: SimHei, Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.sans-serif: SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
解决方式二:在代码中修改
import matplotlib
指定默认字体
matplotlib.rcParams[‘font.sans-serif’] = [‘SimHei’]
matplotlib.rcParams[‘font.family’]=’sans-serif’
解决负号’-‘显示为方块的问题
matplotlib.rcParams[‘axes.unicode_minus’] = False