matplot 标题、图例、设置中文显示
from matplotlib import pyplot as plt, font_manager# 字体实例对象my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf",size=7.0)# 气温x=range(0,120)# 时间y_1=...
·
from matplotlib import pyplot as plt, font_manager
# 字体实例对象
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf",size=7.0)
# 气温
x=range(0,120)
# 时间
y_1=[random.randint(20,35) for i in range(120)]
y_2 = [random.randint(20, 35) for i in range(120)]
# 格式化x轴标题
_x_labels=["10点{}分".format(i) for i in range(60)]
_x_labels+=["11点{}分".format(i) for i in range(60)]
plt.xlabel("时间",fontproperties=my_font)
plt.ylabel("温度",fontproperties=my_font)
plt.title("温度测试用例",fontproperties=my_font)
#设置表格
plt.grid(alpha=0.4)
# 画图
plt.plot(x, y_1,label="123",linestyle=":")
plt.plot(x, y_2,label="456",linestyle="--")
# 添加图例
plt.legend(prop=my_font,loc="upper left")
# 设置中文显示 fontproperties
plt.xticks(list(x)[::3],_x_labels[::3],rotation=45,fontproperties=my_font)
#显示
plt.show()
更多推荐
所有评论(0)