Skip to content

Commit

Permalink
simple animation in matplotlib
Browse files Browse the repository at this point in the history
  • Loading branch information
teuben committed Jun 30, 2023
1 parent 9b16124 commit 65f181b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions animate2
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 65f181b

Please sign in to comment.