import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style

style.use('fivethirtyeight')
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

def animate(i):
    graph_data = open('data.txt', 'r').read()
    # print(graph_data)
    lines = graph_data.split('\n')
    # print(lines)

    xs = np.array([], dtype='float64')
    ys = np.array([], dtype='float64')

    # xs = []       # this is for an array without numpy
    # ys = []

    for line in lines:
        if (len(line) > 1 ):
            x,y = line.split(',')

            xs = np.append(xs,[float(x)],0)
            ys = np.append(ys,[float(y)],0)

            # xs.append(int(x))
             # ys.append(int(y))

    ax1.clear()
    ax1.plot(xs,ys)

ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()












