39 Create a matplotlib animation from a sequence of image files.
41 Available only if matplotlib and PIL are installed.
46 Glob pattern matching image files.
47 render_gif : bool, optional
48 Whether to render the animation.
50 Dots per inch for the figure.
51 interval : int, optional
52 Delay between frames in milliseconds.
53 repeat_delay : int, optional
54 Delay before repeating the animation.
58 FileNotFoundError : if no images are found for the glob pattern
62 matplotlib.animation.FuncAnimation or None
63 Animation object on rank 0, otherwise None.
69 if shamrock.sys.world_rank() != 0:
72 files = sorted(glob.glob(glob_str))
76 with Image.open(my_file)
as image:
77 image_array.append(image.copy())
80 raise FileNotFoundError(f
"No images found for glob pattern: {glob_str}")
82 pixel_x, pixel_y = image_array[0].size
84 fig = plt.figure(dpi=dpi)
85 plt.gca().set_position((0, 0, 1, 1))
86 plt.gcf().set_size_inches(pixel_x / dpi, pixel_y / dpi)
89 im = plt.imshow(image_array[0], animated=
True, aspect=
"auto")
92 im.set_array(image_array[i])
95 ani = animation.FuncAnimation(
98 frames=len(image_array),
101 repeat_delay=repeat_delay,