pymatplotlib多个figure同时画多个图以及多个图例多个折线图图例负号乱码的问题
import numpy as np
import matplotlib.pyplot as plt
import  matplotlib
需要读取数据模板⽂件,格式如下,⾸先是后续要显⽰的名称,然后是成本价、净值,使⽤【/】分隔
建信50 | 0.8502/0.8499/0.8496    | 0.8263/0.8239/0.8253 | 0.0260/0.0246
富国中正红利 | 1.1273/1.1270/1.1263  | 1.1030/1.1040/1.0960 | 0.0230/0.0310
景顺中正500  | 0.9798/0.9792/0.9780  | 0.9271/0.9250/0.9149 | 0.0542/0.0643
前海开源⼈⼯智能 | 1.0665/1.0653/1.0625 |0.9930/0.9890/0.9870 | 0.0763
易⽅达创业板 | 1.6463/1.6452/1.6434 | 1.5368/1.5377/1.5233 | 0.1075
南⽅价值混合C|1.0843/1.0837/1.0819 | 1.0520/1.0520/1.0490 | 0.0317
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import  matplotlib
font = {
'family' : 'SimHei'
}
<('font', **font)
["006539","NFYXJZHHC","南⽅优选价值混合C","混合型","NANFANGYOUXUANJIAZHIHUNHEC"]
["100032","FGZZHLZSZQ","富国中证红利指数增强","股票指数","FUGUOZHONGZHENGHONGLIZHISHUZENGQIANG"]
["003318","JSZZ500HYZXDBD","景顺中证500⾏业中性低波动","股票指数","JINGSHUNZHONGZHENG500HANGYEZHONGXINGDIBODONG"] ["001986","QHKYRGZNZTHH","前海开源⼈⼯智能主题混合","混合型","QIANHAIKAIYUANRENGONGZHINENGZHUTIHUNHE"] ["004744","YFDCYBETFLJC","易⽅达创业板ETF联接C","联接基⾦","YIFANGDACHUANGYEBANETFLIANJIEC"]
["165312","JXYS50","建信央视50","股票指数","JIANXINYANGSHI50"]
i=1
index=321
subIndex=321
def calc(value):
global index
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('|')
v=value.split('|')
name=v[0]
myValue=[]
for m in v[1].split('/'):
myValue.append(float(m))
curValue=[]
for m in v[2].split('/'):
curValue.append(float(m))
z=[]
#整理差值数据
for i in range(len(day)):
z.append((myValue[i]-curValue[i])*10)
plt.figure(1)
plt.subplot(index)
plt.plot(day, myValue, color = 'blue', linewidth = 2.0, linestyle = '-',label="持仓成本价")
plt.plot(day, curValue, color = 'red', linewidth = 2.0, linestyle = '--',label="当前净值")
plt.legend()  #显⽰上⾯的label
plt.title(name) #添加标题
plt.figure(2)
plt.subplot(index)
plt.plot(day, z, color = 'red', linewidth = 2.0, linestyle = '-',label="差值")
matplotlib中subplotplt.legend()  #显⽰上⾯的label
plt.title(name+"差值") #添加标题
index=index+1
return z
def sub(name,value):
plt.figure(1)
plt.subplot(index)
index=index+1
plt.plot(day, value, color = 'red', linewidth = 2.0, linestyle = '-',label="差值")
plt.legend()  #显⽰上⾯的label
plt.title(name+"差值") #添加标题
with open("./a.txt",'r', encoding='UTF-8') as file:
for line in file:
z=calc(line)
name=(line.split('|'))[0] #print(name)
plt.show()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。