在用python的 matplotlib 畫圖的時候,在圖表上面有中文亂碼問題,如下的:
解決過程:
平台:windows,python2.7
步驟一:打開設置文件
會顯示matplotlibrc文件的地址: E:\Anaconda2-4\lib\site-packages\matplotlib\mpl-data\matplotlibrc
步驟一:打開設置文件
import matplotlib
matplotlib.matplotlib_fname()
步驟二:修改matplotlibrc文件
將文件中的
#font.family: sans-serif
font.family: Microsoft YaHei
import matplotlib
matplotlib.use('qt4agg')
#指定默認字體
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family']='sans-serif'
#解決負號'-'顯示為方塊的問題
matplotlib.rcParams['axes.unicode_minus'] = False
pl.plot([-1,2,-5,3])
pl.title(u'中文')
pl.show()
