I am trying to use Matplotlib to visualize some measurements. The measurements typically last about 24hrs and will include ~30k lines of data in the csv. I've been struggling mostly with getting my plots to actually animate. I can execute the code and it will display a snapshot up to the current point in time but nothing else. When I try to autoscale it, nothing plots and it just defaults to a view of -.6 to +.6 on both axes. Am I supposed to call plt.draw() for this to work? This is what I have so far:
import numpy as np
import datetime as dt
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import animation
FMT = '%Y-%m-%d %H:%M:%S.%f'
data = np.genfromtxt('sampleData.csv', delimiter=',', skip_header=5,
names=['x', 'y', 'z', 'w'], dtype=['object', 'int8', 'int8', 'float'])
mytime = [dt.datetime.strptime(i.decode('ascii'), FMT) for i in data['x']]
thickness = data['w']
fig = plt.figure()
axes = fig.add_subplot(111)
line, = axes.plot([], [], '.')
plt.show(block=False)
def init():
line.set_data([],[])
return line,
fig.canvas.draw()
def animate(i):
xdata = mytime[:i]
ydata = thickness[:i]
line.set_data(xdata, ydata)
plt.draw()
axes.relim()
axes.autoscale(True,'both',True)
axes.autoscale_view(True,True,True)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
interval=0, blit=True)
plt.show()
This is a sample line of data from the CSV:
2013-09-25 14:51:15.329091,1,0,439.80,,,,0,0,
animationand talk about incoming data over a period of time, which implies an input data stream. So - can you explain what's happening - is there another process constantly appending to / replacing the.csvand you want to update the plot as the new data comes in? Or do you want to animate the data in thecsvas if it is incoming in "real time"? Or something else?