使用 matplotlib.ArtistAnimation 的动画标题

发布于 2025-01-11 12:13:39 字数 888 浏览 2 评论 0原文

我有以下使用 matplotlib.animations 的脚本,它随时间返回动画收益率曲线图,效果很好:

test = pd.read_csv("test.csv")
test = test.iloc[:, 1:]
test = test.to_numpy()
date = test.iloc[:, 0]

plots = []
fig, ax = plt.subplots()
for i in test:
    plots.append(ax.plot(tenor, i, color="b"))
ani = animation.ArtistAnimation(fig, plots, interval=30, repeat_delay=1000)
plt.show()

但现在我还希望每条曲线的日期时间也进行动画处理(如下所示: http://freerangestats.info/blog/2019/04/20/yield-curve),所以我尝试了这个,但收到以下错误消息:“list”对象没有属性“set_visible”

plots = []
fig, ax = plt.subplots()
for i, d in zip(test, date):
    text = ax.text(-5, 60, f"{d}")
    plots.append([ax.plot(tenor, i, color="b"), text])
ani = animation.ArtistAnimation(fig, plots, interval=30, repeat_delay=1000)
plt.show()

感谢 ! :)

I have the following script using matplotlib.animations that returns animated yield curve plot over-time which work fine :

test = pd.read_csv("test.csv")
test = test.iloc[:, 1:]
test = test.to_numpy()
date = test.iloc[:, 0]

plots = []
fig, ax = plt.subplots()
for i in test:
    plots.append(ax.plot(tenor, i, color="b"))
ani = animation.ArtistAnimation(fig, plots, interval=30, repeat_delay=1000)
plt.show()

But now I also want that the date-time of each curve to be also animated (like here : http://freerangestats.info/blog/2019/04/20/yield-curve), so i tried this but I got the following error message : 'list' object has no attribute 'set_visible'

plots = []
fig, ax = plt.subplots()
for i, d in zip(test, date):
    text = ax.text(-5, 60, f"{d}")
    plots.append([ax.plot(tenor, i, color="b"), text])
ani = animation.ArtistAnimation(fig, plots, interval=30, repeat_delay=1000)
plt.show()

Thank ! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文