【发布时间】:2015-05-26 14:56:32
【问题描述】:
我有一个数据流,每秒给我 125 个浮点数,我想实时绘制它们。目前我的代码如下所示:
Code to read data from stream
counter = 0
while True:
counter = counter+1
data from stream (x values)
当然,实际上代码看起来有点复杂,但我认为这会使提供建议更容易。
我正在考虑将图形保存为文件:
counter=0
a_data=np.zeros(100,float) #this is limited to 100 floats
while True:
counter = counter+1
bytestring = sock.recv(51) # this is the stream data
raw = struct.unpack(pp,bytestring) # this is the unpacked data
twentyfive = (raw[25]-15310)*0.0265 # this is the x value
a_data[counter] = twentyfive
plt.plot(a_data)
print(twentyfive)
plt.savefig('test.png')
time.sleep(0.01)
问题在于数据波动很大,因此过于混乱而无济于事。图表应向右移动。此外,它还不够快。出于这个原因,我正在考虑使用 pyqtgraph,但我不知道如何在我在网上找到的任何示例中将我的 x 值(每秒 125 微伏值)和 y 值(计数器给出的时间步长)提供给 pyqtgraph迄今为止。任何帮助将不胜感激。
【问题讨论】:
-
这是一个非常广泛的问题。尽管如此,我认为使用 matplotlib 对于每秒 125 次更新来说太慢了。
标签: python plot real-time live pyqtgraph