在代码中动态设置(推荐方式)
这种方式不需要修改配置文件,比较方便,推荐该方法,下面是具体步骤:
首先要再python脚本中的开头加上后面的内容:#-*- coding: utf-8 -*-,即用utf8编码
然后在代码中动态设置字体,下面是主要的几行代码
- from matplotlib.font_manager import FontProperties
- import matplotlib.pyplot as plt
- font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
- plt.xlabel(u"电压差(V)", fontproperties=font)
- plt.ylabel(u"介质损耗角差(度)", fontproperties=font)
- plt.title(u"介质损耗角和荷电状态SOC关系图",fontproperties=font)