I am trying to make a live plot in matplotlib, meaning that the data is coming from a CSV file that keeps getting updated with new data. So far, I can't succeed to make the plot update continually.
My intention is that I want that with time passing the graph old point will get out of the plot figure. Can someone help me please?
This is my code:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import csv
import time
fig=plt.figure()
ax1=fig.add_subplot(1,1,1)
def animate(i):
graph_data=open('DATA.csv')
xs=[]
ys=[]
for line in graph_data:
time,hrt=line.split(',')
xs.append(float(time))
ys.append(float(hrt))
ax1.clear()
ax1.plot(xs,ys,'b',linewidth=0.5)
ani=animation.FuncAnimation(fig,animate,interval=8)
plt.show()