python中的matplotlib模塊默認不支持中文的顯示,中文會顯示亂碼,如下圖的紅框所示:
使用matplotlib_fname()會顯示Matplotlib配置文件的保存位置,如下所示:
>>>import matplotlib
>>>matplotlib.matplotlib_fname()
>>>'D:\\Python\\Python36\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc'
打開該文件,找到如下代碼:
#font.family : sans-serif
上面這一行設置了Matplotlib的默認字體,取消這一行前面的註釋符號(#),並將後面的sans-serif修改爲本地已有的中文字體,例如使用微軟雅黑:
font.family : Microsoft YaHei