fix: plot_wave plt.show() crash when called non-interactively

Add show=False parameter to plot_wave(); when called from dynamics.py,
pass show=False and set matplotlib Agg backend to avoid NonGuiException.
Also print full traceback on failure for easier debugging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-13 08:10:16 +08:00
parent d371b28acc
commit 1cefe184d7
2 changed files with 13 additions and 4 deletions
+6 -3
View File
@@ -167,7 +167,7 @@ def compute_energy(x, y, z, vx, vy, vz, masses, mass_arr,
return ek_sys, us_sys, ug_sys, ugr_sys
def plot_wave(output_dir, save_gif=False, save_mp4=False):
def plot_wave(output_dir, save_gif=False, save_mp4=False, show=True):
"""主绘图函数:读取 display.txt 并生成波形+能量动画。
Args:
@@ -360,8 +360,11 @@ def plot_wave(output_dir, save_gif=False, save_mp4=False):
except Exception as e:
print(f"[plot_wave] 警告: MP4 输出失败 ({e}),跳过")
# ── 最后显示动画窗口 ──
plt.show()
# ── 最后显示动画窗口(仅直接运行时)──
if show:
plt.show()
else:
plt.close(fig)
return gif_path