python画k线_python用matplotlib画K线

importmatplotlib.pyplotaspltimportmatplotlib.financeasmpfwithopen('SH#600004.txt')asobj:text=obj.readlines()#vol成交量amo成交额baseinfo=text[0]dayinfo=text[2:-1]date_list...

import matplotlib.pyplot as plt

import matplotlib.finance as mpf

with open('SH#600004.txt') as obj:

text=obj.readlines()

# vol 成交量 amo成交额

baseinfo=text[0]

dayinfo=text[2:-1]

date_list =[dayinfo[i].split(',')[0] for i in range(len(dayinfo))]

open_list =[dayinfo[i].split(',')[1] for i in range(len(dayinfo))]

high_list =[dayinfo[i].split(',')[2] for i in range(len(dayinfo))]

low_list =[dayinfo[i].split(',')[3] for i in range(len(dayinfo))]

close_list=[dayinfo[i].split(',')[4] for i in range(len(dayinfo))]

quotes=zip(date_list,open_list,high_list,low_list,close_list)

#N=100

#open_list[:N],high_list[:N],low_list[:N],close_list[:N]

fig,ax=plt.subplots()

mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green')

plt.title(baseinfo)

plt.xlabel(date_list)

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签

plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

plt.show()

#报错信息

#TypeError: unsupported operand type(s) for -: 'str' and 'str'

请问应该怎么改

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值