python之matplotlib使用系统字体
- 导包
from matplotlib.font_manager import FontProperties
- 调用本机字体库设置字体
font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)
- 其中,
simhei.ttf
是自己电脑中的字体,如何找到呢,在路径C:\Windows\Fonts
的文件夹中,有如下字体,如下图
带有常规字样的字体,如上图红圈中的内容,可以点击属性,找到字体,如下图 - 关于使用,绘图的时候,直接调用就好
plt.xlabel("数量",FontProperties=font)