简单问题:Matplotlib 绘制多条二维线

发布于 2025-01-17 09:14:49 字数 283 浏览 1 评论 0原文

我想在 Mat-Plot-Lib 中绘制多条 2D 线,但希望将它们动画化到绘图上。 换句话说,我希望出现一行,然后是另一行,然后是另一行,依此类推...... 目前,我有以下内容:

for line in lines:
 y = line
 plt.plot(x,y,'-r')
 plt.grid()
 plt.show()
 time.sleep(1)

但是,最终发生的情况是我得到了一堆不同的图,每个图都绘制了下一行。我需要所有这些线一条接一条地出现在同一张图表上。 我该怎么做?

I want to draw multiple 2D lines in Mat-Plot-Lib, but want to animate them onto a plot.
In other words, I want one line to appear, then another, then another, and so on...
Currently, I have the following:

for line in lines:
 y = line
 plt.plot(x,y,'-r')
 plt.grid()
 plt.show()
 time.sleep(1)

However, what ends up happening is that I get a bunch of different plots, each plotting the next line. I need all of these lines to appear on the same graph, one after another.
How can I do this?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2025-01-24 09:14:49

绘制线之后的plt.show:

for line in lines:
 y = line
 plt.plot(x,y,'-r')
 plt.grid()
 time.sleep(1)
plt.show()

plt.show after the lines are drawn:

for line in lines:
 y = line
 plt.plot(x,y,'-r')
 plt.grid()
 time.sleep(1)
plt.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文