解决步骤:
下载SimHei.ttf 字体文件,放在/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/fonts/ttf/ 目录下面,记住要设置好访问权限
一般默认路径是这里,当然如果不放心可以执行 locate -b /mpl-data 查看相应具体路径
下载路径:https://download.csdn.net/download/daixiangzi/11049629,当然网上也有免费的哇.网络不好的可以下我这个
from matplotlib import pyplot as plt
import matplotlib
import numpy as np
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import matplotlib.font_manager as fm
myfont = fm.FontProperties(fname='/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/fonts/ttf/SimHei.ttf')
data = np.random.randn(1000)
plt.hist(data,bins=40,density=0,facecolor="blue",edgecolor="black",alpha=0.7)
plt.xlabel("区间",fontproperties=myfont)
plt.ylabel("频率",fontproperties=myfont)
plt.title("直方图",fontproperties=myfont)
plt.show()