【发布时间】:2021-12-26 02:29:45
【问题描述】:
我的目标是查看股票的直方图如何随时间变化。所以我想在指定时间为差异设置动画。根据网络上的一些文章,我尝试了以下方法。但我没有得到一些直方图数据。我对 matplotlib 中动画方式的理解有什么问题?
import pandas_datareader as web
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
stock = 'ALB'
df = web.DataReader(stock, 'yahoo', "01.01.2021", "14.11.2021")
def update_hist(step):
plt.cla()
df_step = df[:][step:step+30]
df_step.hist(column=stock)
animation.FuncAnimation(fig, update_hist, fargs=([1, 30, 60, 90, 120]))
plt.show()
【问题讨论】:
标签: python pandas animation histogram stock