import lcm
from exlcm import data_structures
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from itertools import count
import select
import time
import threading
import multiprocessing
from drawnow import drawnow
x=[]
y=[]
index = count()
def my_handler(channel, data): 
    msg = data_structures.decode(data)
    x.append(next(index))
    y.append(msg.y)


def make_fig():
    plt.plot(x,y)

plt.ion()  # enable interactivity
fig = plt.figure() 

lc = lcm.LCM()
lc.subscribe("BRUH",my_handler)


try:
    while True:
        lc.handle()
        drawnow(make_fig)
except KeyboardInterrupt:
    pass