From 84770f4b08090387cc553bd6f13fd6b001d56518 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Fri, 5 Dec 2025 11:57:22 +0100 Subject: [PATCH] Make the animation 3D --- animate_result.py | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/animate_result.py b/animate_result.py index 486cb5b..556d579 100755 --- a/animate_result.py +++ b/animate_result.py @@ -1,42 +1,53 @@ #!/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): @@ -56,13 +67,15 @@ def matAniFromFile(filename): 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(); -- 2.30.2