【发布时间】:2014-02-24 14:39:39
【问题描述】:
经过一整天的反复试验,我将我的发现发布为对可能遇到此问题的其他人的帮助。
在过去的几天里,我一直在尝试模拟来自 netCDF 文件的一些雷达数据的实时绘图,以使用我为学校项目构建的 GUI。我尝试的第一件事是使用 matplotlib 的“交互模式”对数据进行简单的重绘,如下:
import matplotlib.pylab as plt
fig = plt.figure()
plt.ion() #Interactive mode on
for i in range(2,155): #Set to the number of rows in your quadmesh, start at 2 for overlap
plt.hold(True)
print i
#Please note: To use this example you must compute X, Y, and C previously.
#Here I take a slice of the data I'm plotting - if this were a real-time
#plot, you would insert the new data to be plotted here.
temp = plt.pcolormesh(X[i-2:i], Y[i-2:i], C[i-2:i])
plt.draw()
plt.pause(.001) #You must use plt.pause or the figure will freeze
plt.hold(False)
plt.ioff() #Interactive mode off
虽然这在技术上有效,但它也禁用了缩放功能,以及平移,以及一切!
对于雷达显示图,这是不可接受的。请参阅下面的解决方案。
【问题讨论】:
-
恭喜一切顺利!提出问题并在stackoverflow上发布您自己的答案是非常好的(并且鼓励)。但是,最好将问题和答案分开。现在,你把它们放在一起。如果有机会,请发布问题的后半部分作为答案。一天左右后,您也可以将其标记为已接受的答案。顺便说一句,很好的问题和很好的答案!
-
另外,请注意,
imshow(与interp='none'匹配pcolormesh)将是动画的更好选择。它的渲染速度要快得多,尤其是对于大型数据集。此外,如果您更改动画以更新现有对象而不是在旧对象之上添加新对象,您将获得更好的性能(您当前的方法可能每帧都会变慢)。无论如何,如果您在访问“实时”数据流后需要更好的性能,只是建议。
标签: python animation matplotlib