python中设置中文字体,不过不能存为eps,比较鸡肋

在代码中动态设置(推荐方式)
这种方式不需要修改配置文件,比较方便,推荐该方法,下面是具体步骤:
首先要再python脚本中的开头加上后面的内容:#-*- coding: utf-8 -*-,即用utf8编码
然后在代码中动态设置字体,下面是主要的几行代码

[python]  view plain  copy
  1. from matplotlib.font_manager import FontProperties  
  2. import matplotlib.pyplot as plt  
  3. font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)  
  4.   
  5. plt.xlabel(u"电压差(V)", fontproperties=font)  
  6. plt.ylabel(u"介质损耗角差(度)", fontproperties=font)  
  7. plt.title(u"介质损耗角和荷电状态SOC关系图",fontproperties=font)                                

猜你喜欢

转载自blog.csdn.net/wasefadg/article/details/80804086