【发布时间】:2021-05-24 13:07:19
【问题描述】:
谁能看到我的代码到底有什么问题?我正在尝试生成我的结果的动画图,以查看它随时间的演变,结果只是我的数据的完整图,而不是更新动画。
sampleText.txt文件只是一个大小为(5000, 1)的numpy数组,数组的前5个条目是[[-0.01955058],[ 0.00658392[,[-0.00658371],[-0.0061325 ],[-0.0219136 ]]
import matplotlib.animation as animation
import time
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot()
def animate(i):
x = np.linspace(0, len(dataArray), len(dataArray))
y = []
for eachLine in x:
y.append(eachLine * 10)
ax1.clear()
ax1.plot(x, y, color = 'red', alpha = 0.5)
ani = animation.FuncAnimation(fig, func = animate)
plt.show()
【问题讨论】:
-
那么问题出在哪里?你有一半的问题和一半的minimal reproducible example 这里
-
@MadPhysicist 请查看我对问题的更新。我已经简化了示例并更清楚地显示了问题。我得到了整个数据的完整图,而不是我想要的更新动画
-
感谢您的回复。你能提供一个数据样本吗?比如打电话给
np.arange或np.random,而不仅仅是口头描述? -
我不是 100% 确定你的意思,但我的这是我的 '(5000,1)' numpy 数组的前 5 个条目看起来像 '[[-0.01955058] [ 0.00658392 ] [-0.00658371] [-0.0061325 ] [-0.0219136 ]]'
-
您不需要确切的数组。只需提供一些生成类似内容的代码即可。请参阅minimal reproducible example 以供参考
标签: python matplotlib matplotlib-animation