设置matplotlib中文显示

  1. 安装系统语言管理fontconfig
    yum -y install fontconfig
  2. 将windows中 windows/fonts中的字体复制到Linux中
    Linux目录路径: /usr/shared/fonts/chinese
    注意修改权限为 755
  3. 在当前文件夹生成字体检索信息
    mkfontscale
    mkfontfir
    fc-cache -fv
  4. 导入到matplotlib程序中
from matplotlib.font_manager import *
import matplotlib.pyplot as plt

myfont = FontProperties(fname='/usr/share/fonts/chinese/msyhl.ttc')
matplotlib.rcParams['axes.unicode_minus']=False


fig = plt.figure()
ax = fig.add_subplot(111)

ax.text(0,0,u'-你好',fontproperties=myfont)
ax.set_axis_off()

plt.show()

猜你喜欢

转载自blog.csdn.net/u014134138/article/details/78509655
今日推荐