`
belldeep
  • 浏览: 39096 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

python : pyecharts K线图

阅读更多
官方中文版帮助文档 http://pyecharts.org/#/zh-cn/
Kline/Candlestick(K线图)
红涨蓝跌
Kline.add() 方法签名
add(name, x_axis, y_axis, **kwargs)
name -> str
图例名称
x_axis -> list
x 坐标轴数据
y_axis -> [list], 包含列表的列表
y 坐标轴数据。数据中,每一行是一个『数据项』,每一列属于一个『维度』。
数据项: [open, close, lowest, highest] (即:[开盘值, 收盘值, 最低值, 最高值])
实例: kline1.py
import os, sys
from pyecharts import Kline

if len(sys.argv) ==2:
    fcode = sys.argv[1]
else:
    print('usage: kline1.py fcode ')
    sys.exit(1)

if len(fcode) !=6:
	print(' fcode is char(6)')
	sys.exit(2)

file1 = 'M'+fcode +'.csv'
file2 = 'M'+fcode +'.html'

if not os.path.exists(file1):
	print(file1 +' is not exists.')
	sys.exit(3)

# 数据项: [open, close, lowest, highest] (即:[开盘值, 收盘值, 最低值, 最高值])
alist = []
vlist = []
fp = open(file1,'r')
fp.readline() # 跳过第1行表头: ym,open,close,low,high
for line in fp:
	ym,open,close,low,high = line.strip().split(',')
	alist.append(ym)
	vlist.append([open,close,low,high])
print(str(len(alist)))
kline = Kline(fcode+" 月K线图")
kline.add(fcode, alist, vlist)
kline.render(path=file2)


参考 https://blog.csdn.net/qtlyx/article/details/85221503
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics