此代码构造一个matplotlib图,使用来自网页的get_data函数以open,high,low,close格式获取数据,并使用FuncAnimation将这些值每五分钟附加到一个列表,然后更新烛台图表。然而,y轴值不正确,因为它们仅显示1-7并且应当是当前S& P价格约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()
答案 0 :(得分:1)
答案 1 :(得分:1)
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=plt.gca()
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()