【发布时间】:2017-09-26 13:52:24
【问题描述】:
此代码构造一个 matplotlib 图形,使用 get_data 函数从网页以开盘、高盘、低盘、收盘格式获取数据,并使用 FuncAnimation 每五分钟将这些值附加到列表中,然后更新烛台图。但是,y 轴值不正确,因为它们仅显示 1-7,并且应该是当前标普价格 2500 左右。如何解决?
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import matplotlib.animation as animation
from matplotlib import style
from es_cme_quote import get_data
import numpy as np
style.use('ggplot')
fig=plt.figure()
ax= fig.add_subplot(111)
o_array=[]
h_array=[]
l_array=[]
c_array=[]
def update(dummy):
[O,H,L,C]=get_data()
def append_var(x,y):
y.append(x)
append_var(O[0],o_array)
append_var(H[0],h_array)
append_var(L[0],l_array)
append_var(C[0],c_array)
ax.clear()
candlestick2_ohlc(ax,o_array,h_array,l_array,c_array,
width=.8,colorup='g',colordown='r',alpha=1.0)
anime=animation.FuncAnimation(fig,update,interval=300000)
plt.show()
【问题讨论】:
标签: python matplotlib