python使用 numpy+matplotlib 库画股票k线图

下面是 python 使用 numpy+matplotlib 库画股票k线图的完整例子

python使用 numpy+matplotlib 库画股票k线图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -- 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()

本文网址: https://pylist.com/topic/142.html 转摘请注明来源

Suggested Topics

python 高效的list 去重方式

list 去重是编程中经常用到的,python 的去重方式很灵活,下面介绍多种去重方式,并比较得出最高效的方式。...

在 Ubuntu 16.04.6 LTS 系统上安装 Python 3.6.3

自己的阿里云一个 VPS 用的是系统 Ubuntu 16.04.6 LTS,自带的python版本是 `2.7.12` 与 `3.5.2`,有时候要用到 python `3.6`,又不想卸掉原来版本。下面介绍安装 python 3.6.3 的过程,因为版本较旧,遇到一些坑,这里记录一下。...

Leave a Comment