Skip to content

Instantly share code, notes, and snippets.

@jzrake
Created November 16, 2017 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzrake/a1c89f789d4f243e090d529a00ea96fe to your computer and use it in GitHub Desktop.
Save jzrake/a1c89f789d4f243e090d529a00ea96fe to your computer and use it in GitHub Desktop.
Starter Python script for making animations with matplotlib
import argparse
import numpy as np
import h5py
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
class TrackFigure(object):
def __init__(self, fig, filename):
self.file = h5py.File(filename, 'r')
self.ax1 = fig.add_subplot(1, 1, 1)
self.line, = self.ax1.plot([], [], '-o')
self.ax1.set_xlim(0, 100)
self.ax1.set_ylim(0, 100)
def load_frame(self, frame):
self.line.set_data(range(frame), range(frame))
return self.line,
def make_animation(filename):
fig = plt.figure(figsize=[10,6])
animation = FuncAnimation(
fig,
TrackFigure(fig, filename).load_frame,
frames=range(100),
interval=20,
blit=True)
plt.show()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("filename")
args = parser.parse_args()
make_animation(args.filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment