#!/usr/bin/env python

import sys
import serial
import matplotlib
matplotlib.use("tkAgg")
import matplotlib.pyplot as plt
import numpy as np

#sudo apt-get install python3-tk
#pip install numpi
#pip install matplotlib

ser = serial.Serial('/dev/ttyUSB1', 450000)
ser.flushInput()

plot_window = 1000

ser_bytes = ser.readline()
str = ser_bytes[:-2].decode("utf-8")
spl = str.split(",")
f2 = float(spl[1])
y_var = np.array(plot_window * [f2])

y_var_1 = np.array(plot_window * [f2])

plt.ion()
fig = plt.figure()

ax1 = fig.add_subplot(111, label="1")
line, = ax1.plot(y_var, color="#ff0000")

ax2 = ax1
line2, = ax2.plot(y_var_1, color="#0000ff")

plt.show()

count = 0
while True:
	ser_bytes = ser.readline()
	str = ser_bytes[:-2].decode("utf-8")
	spl = str.split(",")
	f1 = float(spl[0])
	f2 = float(spl[1])

	y_var = np.append(y_var, f2)
	y_var = y_var[1:plot_window+1]
	line.set_ydata(y_var)

	y_var_1 = np.append(y_var_1, f1)
	y_var_1 = y_var_1[1:plot_window+1]
	line2.set_ydata(y_var_1)

	if count == 2:
		ax1.relim()
		ax1.autoscale_view()

		fig.canvas.draw()
		fig.canvas.flush_events()	
		count = 0

	count += 1

def main() -> None:
	...

if __name__ == "__main__":
	main()
    