From 5b69600408375bddbeede7cb475d4abcadf07f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A9vis=20Morvany?= Date: Tue, 21 Jan 2025 09:55:33 +0100 Subject: [PATCH] Fix animation frames ordering --- projects/01_wave/python/animate.py | 4 +++- projects/01_wave/python/animate_3d.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/01_wave/python/animate.py b/projects/01_wave/python/animate.py index 6e27cbc..cabe209 100644 --- a/projects/01_wave/python/animate.py +++ b/projects/01_wave/python/animate.py @@ -11,6 +11,7 @@ from matplotlib import * from matplotlib.pyplot import * import matplotlib.animation as animation +import re # ______________________________________________________________________________ # RCParams - personalize the figure output @@ -50,7 +51,8 @@ file_list = glob.glob("{}/grid_*.json".format(file_path)) -file_list = sorted(file_list) +iter_number_re = re.compile(r"{}/grid_(\d+).json".format(file_path)) +file_list = sorted(file_list, key=lambda p: int(iter_number_re.match(p).group(1))) # ______________________________________________________________________________ # Animation function diff --git a/projects/01_wave/python/animate_3d.py b/projects/01_wave/python/animate_3d.py index 103e5a8..64ba190 100644 --- a/projects/01_wave/python/animate_3d.py +++ b/projects/01_wave/python/animate_3d.py @@ -12,6 +12,7 @@ from matplotlib.pyplot import * import matplotlib.animation as animation from mpl_toolkits.mplot3d import Axes3D +import re # ______________________________________________________________________________ # RCParams - personalize the figure output @@ -51,7 +52,8 @@ file_list = glob.glob("{}/grid_*.json".format(file_path)) -file_list = sorted(file_list) +iter_number_re = re.compile(r"{}/grid_(\d+).json".format(file_path)) +file_list = sorted(file_list, key=lambda p: int(iter_number_re.match(p).group(1))) # ______________________________________________________________________________ # Animation function