Python中的实时绘图
我有一个每秒125个浮点数的数据流,我想实时绘制它们。目前,我的代码如下所示:Python中的实时绘图,python,plot,real-time,live,pyqtgraph,Python,Plot,Real Time,Live,Pyqtgraph,我有一个每秒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)
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,这是我目前在线找到的任何示例。任何帮助都将不胜感激。PyQtGraph是一个不错的选择,实时绘制125个样本/秒应该没有问题。有几种方法可用于绘制实时滚动数据,PyQtGraph中有一个很好的示例文件显示了这一点: 安装PyQtGraph后,可以通过在Python解释器中运行以下命令来运行示例:
import pyqtgraph.examples
pyqtgraph.examples.run()
选择“滚动绘图”示例。这是一个非常广泛的问题。然而,我认为使用matplotlib速度太慢,每秒更新125次。