#!/usr/bin/env python3
import sys
-import matplotlib.pyplot as plt
import numpy as np
-import matplotlib.animation as animation
import scipy as scp
+import matplotlib.pyplot as plt
+import mpl_toolkits.mplot3d.axes3d as p3
+import matplotlib.animation as animation
class ExtLine:
- def __init__(self, line, name_x, name_y):
+ def __init__(self, line, name_x, name_y, name_z):
self.line = line;
self.name_x = name_x;
self.name_y = name_y;
+ self.name_z = name_z;
class MatAnimation:
def __init__(self, data_dict = dict()):
self.data = data_dict;
self.lines = [];
- self.fig, self.axes = plt.subplots();
+ self.fig = plt.figure();
+ self.axes = self.fig.add_subplot(projection="3d");
- def plot(self, name_x, name_y):
+ def plot(self, name_x, name_y, name_z):
+ line, = self.axes.plot(
+ self.data[name_x],
+ self.data[name_y],
+ self.data[name_z])
self.lines.append(
ExtLine(
- self.axes.plot(self.data[name_x], self.data[name_y])[0],
+ line,
name_x,
- name_y));
+ name_y,
+ name_z));
def show(self):
self.animation = animation.FuncAnimation(
self.fig, self.update, len(self.data["time"]),
- interval = 1);
+ interval = 100,
+ blit=False);
plt.show();
def update(self, frame):
for line in self.lines:
- line.line.set_xdata(self.data[line.name_x][:frame]);
- line.line.set_ydata(self.data[line.name_y][:frame]);
+ line.line.set_data([
+ self.data[line.name_x][:frame],
+ self.data[line.name_y][:frame]]);
+ line.line.set_3d_properties(self.data[line.name_z][:frame]);
return [line.line for line in self.lines];
def transpose_strings(array):
inds = data["dataInfo"][1];
ani = MatAnimation();
for i in inds:
- ani.data[names[i - 1]] = pure_data[i - 1, :-1];
+ ani.data[names[i - 1]] = data["data_2"][i - 1, :-1];
return (ani);
ani = matAniFromFile(sys.argv[1]);
-ani.plot("p[1].pos[1]", "p[1].pos[2]");
-ani.plot("p[2].pos[1]", "p[2].pos[2]");
-ani.plot("p[3].pos[1]", "p[3].pos[2]");
-ani.plot("p[4].pos[1]", "p[4].pos[2]");
+for i in range(1,10):
+ ani.plot(
+ "p[" + str(i) + "].pos[1]",
+ "p[" + str(i) + "].pos[2]",
+ "p[" + str(i) + "].pos[3]"
+ );
ani.show();