【发布时间】:2019-12-09 17:33:18
【问题描述】:
我有一个 numpy 数组,我在循环外使用 np.zeros 对其进行了初始化。 该数组使用 for 循环中的某个函数进行更新。我希望绘制随着每次迭代而变化的数组。
我在这里看到的大多数答案都是针对列表而不是 ndarray。 我看过以下链接。其中一些我已经尝试修改以达到我的目的,但无济于事。
How to update a plot in matplotlib?
https://github.com/stsievert/python-drawnow/blob/master/drawnow/drawnow.py @Scott Sievert,我也看到了你的代码。但不幸的是,我一直无法弄清楚如何修改它。
Real-time plotting using matplotlib and kivy in Python
Real-time plotting using matplotlib and kivy in Python
Real time trajectory plotting - Matplotlib
https://realpython.com/python-matplotlib-guide/
https://gist.github.com/vaclavcadek/66c9c61a1fac30150514a665c4bcb5dc
http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
所以基本上我想实时查看 ndarray y 的值。 (见下面的代码)
我将它作为脚本运行。@Scott Staniewicz
from numpy.random import random_sample
from numpy import arange, zeros
x = arange(0, 10)
y = zeros((10, 1))
for i in range(10):
y[i] = sin(random_sample())
【问题讨论】:
-
您是否有任何代码示例几乎可以工作,但不完全?我已经看到了几种绘制更新 ndarray 图像的方法,有些更复杂,但更难工作,所以看看你要做什么会很有帮助
-
另外,了解您如何尝试运行此代码也会很有帮助:例如作为脚本,在 iPython 终端中,在 jupyter 笔记本中......其中一些情况比其他情况更容易工作
-
@ScottStaniewicz 我已经在编辑中添加了信息
标签: python numpy matplotlib numpy-ndarray