如何修复用于实时更新股票图的代码?

时间:2019-07-13 19:18:00

标签: python python-3.x csv matplotlib

我想修正拥挤的日期是轴,并且在图形至少更新一次之后立即出现一条线,我在python中不是很好。我该如何解决我的问题?

代码

import datetime as dt
import pandas_datareader as web
import matplotlib.pyplot as plt
import csv
import matplotlib.animation as animation

start = dt.datetime(2019, 4, 1)
fig = plt.figure(1)
ax1 = fig.add_subplot(1, 1, 1)
b = []
c = []
def animate(i):
    a = web.get_data_yahoo('AAPL', start, dt.datetime.now())
    f = open(r'C:\Users\HOME-PC\Desktop\python\people1.csv', 'w')
    a.to_csv(f)
    f.close()
    with open('people1.csv', 'r') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            b.append(row['Date'])
            c.append(round(float(row['Close'])))
    ax1.clear()
    ax1.plot(b, c)
    plt.title(" Stock Market Price Of ")
    plt.ylabel("Price in USD")
    plt.xlabel("Year")
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()

至少更新一次之前的输出:

enter image description here

至少更新一次后输出:

enter image description here

0 个答案:

没有答案