重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

利用pythonnumpy+matplotlib绘制股票k线图的方法-创新互联

一、python numpy + matplotlib 画股票k线图

创新互联主要从事网站设计制作、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务原州,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
# -- coding: utf-8 --
import requests
import numpy as np  
from matplotlib import pyplot as plt  
from matplotlib import animation
 
fig = plt.figure(figsize=(8,6), dpi=72,facecolor="white")
axes = plt.subplot(111)
axes.set_title('Shangzheng')
axes.set_xlabel('time')
line, = axes.plot([], [], linewidth=1.5, linestyle='-')
alldata = []
 
def dapan(code):
	url = 'http://hq.sinajs.cn/?list='+code
	r = requests.get(url)
	data = r.content[21:-3].decode('gbk').encode('utf8').split(',')
	alldata.append(data[3])
	axes.set_ylim(float(data[5]), float(data[4]))
	return alldata
 
def init():
	line.set_data([], [])
	return line
 
def animate(i): 
 	axes.set_xlim(0, i+10)
 	x = range(i+1)
 	y = dapan('sh000001')
 	line.set_data(x, y)
 	return line
 
anim=animation.FuncAnimation(fig, animate, init_func=init, frames=10000, interval=5000)
 
plt.show()

网页名称:利用pythonnumpy+matplotlib绘制股票k线图的方法-创新互联
网址分享:http://cqcxhl.cn/article/dhhscg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP