我有一个csv文件,其中包含以下列{time,x,y,z}和大约100000行。我想实时“直播/动画”数据,以便我可以了解正在发生的事情。
尝试:
def generate_pieces(file, piecesize=128):
piece = []
for i, line in enumerate(file):
if (i % piecesize == 0 and i > 0):
yield piece
del piece[:]
piece.append(line)
yield piece
file = csv.reader(open('file_name.csv'))
for piece in generate_pieces(file):
x_data = []
y_data = []
z_data = []
t_vec = []
for row in piece:
x_data.append(row[1])
y_data.append(row[2])
z_data.append(row[3])
d = datetime.datetime.strptime(row[0], '%Y-%m-%d-%H%M%S')
d_simp = (d.hour+ (1/60)*d.minute + (1/3600)*d.second)
conversion = 86400*d.day+3600*d.hour+60*d.minute + d.second
t_vec.append(conversion)
x_data = [int(i) for i in x_data] # Converts values to int type.
y_data = [int(i) for i in y_data]
z_data = [int(i) for i in z_data]
所以我的尝试涉及获取长度为128的数据。从这里我想在实时情节中一次流128个点?我不知道从哪里开始
答案 0 :(得分:1)
考虑使用matplotlib来实现此目的,它可以帮助以动画间隔绘制数据
示例代码
import matplotlib.pyplot as plot
import matplotlib.animation as animation
figure = plot.figure()
axis= figure.add_subplot(1,1,1)
def animateplots(i):
#Prepare data for plot
axis.clear()
axis.plot(x,y,z)
ani = animation.FuncAnimation(figure, animateplots, interval=<intended interval>)
plot.show()
希望我对您的问题的理解是正确的,如果是这样的话,请考虑阅读有关matplotlib的更多信息,以了解图形绘制需求