I'm plotting live data i'm getting from an arduino. on the x axis i'm displaying the time but the axis is becoming too long that everything becomes unreadable. my lists have a max lengt of 10. when it goes over this amount i start shifting the data one place left and add the new data at the back but this doesn't plot like i would like to. when i print the values i see my shiting is working but i'm missing something when plotting. this is my code:
import serial
import datetime as dt
import matplotlib.pyplot as plt
Time = []
Data = []
Data = Data[:10]
Time = Time[:10]
start = 0
j = 0
index = 0
max_Array = 9
array_Plaats = 0
old_Packet = 5
ser = serial.Serial('COM3', 9600, timeout=2)
ser.close()
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
def Array():
global max_Array
global array_Plaats
global start
global packet_Deco
if (array_Plaats <= max_Array and start == 0):
Data.append(packet_Deco)
array_Plaats += 1
Time.append(dt.datetime.now().strftime('%H:%M:%S'))
else:
start = 1
global index
print(index)
if index == max_Array:
index = 0
while index < max_Array:
j = index + 1
Data[index] = Data[j]
Time[index] = Time[j]
index = index + 1
Data[max_Array] = packet_Deco
Time[max_Array] = dt.datetime.now().strftime('%H:%M:%S')
ser.open()
while True:
global packet_Deco
packet = ser.readline()
if (packet != old_Packet):
old_Packet = packet
packet_Deco = int(packet.decode('utf'))
#print(packet_Deco)
Array()
print(Data)
print(len(Time))
line1, = ax.plot(Time, Data, 'r-')
plt.pause(0.0001)
fig.canvas.draw()
fig.canvas.flush_events()