Python3 matplotlib.pyplot 中文乱码 多个直线图 添加图例

#import之后
font = {
    'family' : 'SimHei'
}
matplotlib.rc('font', **font)
# -*- coding:utf-8 -*-
import numpy as np  
import matplotlib.pyplot as plt
import  matplotlib

font = {
    'family' : 'SimHei'
}
matplotlib.rc('font', **font)

day="6-1,6-2,6-3".split(',')
v="建信50 | 0.8502/0.8499/0.8496    | 0.8263/0.8239/0.8253 | 0.0260/0.0246".split('|')
#print(day)
name=v[0]

#print("name",name)

myValue=[]
for m in v[1].split('/'):
    myValue.append(float(m))
curValue=[]
for m in v[2].split('/'):
    curValue.append(float(m))
#print(myValue)
#print(curValue)
z=[]
#整理差值数据
for i in range(len(day)):
    z.append((myValue[i]-curValue[i])*10)
print("差值",z)    
#print(type(z))

plt.figure()  
#plt.plot(day,z)  
#plt.savefig("easyplot.png")  
#plt.show()

plt.plot(day, myValue, color = 'blue', linewidth = 2.0, linestyle = '-',label="持仓成本价")
plt.plot(day, curValue, color = 'red', linewidth = 2.0, linestyle = '--',label="当前净值")
#plt.plot(day, z, color = 'red', linewidth = 2.0, linestyle = '-',label=u"差值")

plt.legend()  #显示上面的label
plt.title(name) #添加标题

plt.show()

 

posted @ 2019-06-04 16:12 Hey,Coder! 阅读(...) 评论(...) 编辑 收藏