osnosn

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::

python_matplotlib_中文字体

转载注明来源: 本文链接 来自osnosn的博客,写于 2021-07-30.

参考

下载字体

  • 首先去网上下载个字体。比如 SimHei.ttf

在matplotlib中设置局部字体

import matplotlib.font_manager
font_zh=matplotlib.font_manager.FontProperties(fname='./SimHei.ttf')
...
plt.title('直方图数据分析与展示',fontproperties=font_zh)

临时注册/载入字体

matplotlib-3.3.4 测试OK

import matplotlib.font_manager
matplotlib.font_manager.fontManager.addfont('./SimHei.ttf')
plt.rcParams['font.family']='SimHei'  #全局指定
...
plt.title('直方图数据分析与展示')

#或者临时指定
ax.set_xlabel('测试',fontfamily='SimHei')
ax.set_title('测试',fontfamily='SimHei')
fig.suptitle('测试',fontfamily='SimHei')
fig.legend(prop='SimHei')

#或者
simhei={'family':'SimHei'}
ax.set_xlabel('测试',fontdict=simhei)
ax.set_title('测试',fontdict=simhei)
fig.suptitle('测试',fontdict=simhei)
fig.legend(prop=simhei)

转载注明来源: 本文链接 https://www.cnblogs.com/osnosn/p/15368381.html
来自 osnosn的博客 https://www.cnblogs.com/osnosn/ .


posted on 2021-10-05 12:17  osnosn  阅读(405)  评论(0编辑  收藏  举报