在代码中动态设置(推荐方式),不需要修改配置文件。推荐该方法,具体步骤:
- 在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)
上述代码重要部分:
fontproperties=font
,可以在制图函数中灵活使用。接下来是在实际运用中,绘制决策树决策节点和叶节点的代码。