From 65f181b5a27efe91bc5a3b8a2a78e39707855510 Mon Sep 17 00:00:00 2001 From: Peter Teuben Date: Thu, 29 Jun 2023 23:18:51 -0400 Subject: [PATCH] simple animation in matplotlib --- animate2 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 animate2 diff --git a/animate2 b/animate2 new file mode 100755 index 0000000..1110168 --- /dev/null +++ b/animate2 @@ -0,0 +1,40 @@ +#! /usr/bin/env python + +import numpy as np +import glob +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +# get the filenames, make sure they are sorted in time +f = glob.glob('run1/tab/LinWave*tab') +f.sort() + +# 1-based columns numbers for now +xcol = 3 +ycol = 5 + +# delay in ms +delay=100 + +# create the figure and axes objects +fig, ax = plt.subplots() + +# function that draws each frame of the animation +def animate(i): + # print(f[i]) + d = np.loadtxt(f[i]).T + x = d[xcol-1] + y = d[ycol-1] + + ax.clear() + ax.plot(x, y) + #ax.set_xlim([0,20]) + #ax.set_ylim([0,10]) + ax.set_title(f[i]) + + +# run the animation +ani = FuncAnimation(fig, animate, frames=len(f), interval=delay, repeat=False) + +plt.show() +