I have a data stream giving me 125 floats per second and I want to plot them live. At the moment my code looks like this:
Code to read data from stream
counter = 0
while True:
counter = counter+1
data from stream (x values)
In reality the code looks a bit more complicated, of course, but this will make giving advice easier, I think.
I was thinking about just saving the graph as a file:
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)
The problem is that the data fluctuates a lot so it's way too cluttered to be helpful. The graph should move to the right. In addition it is by no means fast enough. For this reason I was thinking about using pyqtgraph but I have no idea how to feed my x values (125 microvolt values per second) and y values (the time steps as given by the counter) to pyqtgraph in any of the examples I found online so far. Any help would be greatly appreciated.