From 7e7e1a4185ea986113478a6feb1c39570a71f81a Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Mon, 28 Apr 2025 18:49:06 -0500 Subject: [PATCH] GIF of extrapolation --- calculations/PMM.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/calculations/PMM.py b/calculations/PMM.py index 0ca87db..33af21f 100644 --- a/calculations/PMM.py +++ b/calculations/PMM.py @@ -111,3 +111,39 @@ axs[1].legend() plt.tight_layout() # Adjust spacing between panels plt.show() + +# %% +# animation of eigenvalues +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +# Prepare figure +fig, ax = plt.subplots(figsize=(8, 8)) +ax.scatter(np.real(train_data['k']), np.imag(train_data['k']), label='training') +ax.scatter(np.real(target_data['k']), np.imag(target_data['k']), label='target') +sc = ax.scatter([], [], marker='x', label='predicted') # Placeholder for predicted eigenvalues +ax.set_xlim(-1, 1) # Adjust limits as needed +ax.set_ylim(-1, 1) # Adjust limits as needed +ax.set_xlabel('Re(k)') +ax.set_ylabel('Im(k)') +ax.legend() +ax.set_title('c = ?') + +# Animation function +def update(c): + H = H0 + c * H1 + evals = torch.linalg.eigvals(H).detach().numpy() + sc.set_offsets(np.c_[np.real(evals), np.imag(evals)]) + ax.set_title(f'c = {c:.2f}') + return sc, + +# Create animation +no_frames = 100 +c_steps = np.linspace(min(df['c']), max(df['c']), no_frames) +ani = FuncAnimation(fig, update, frames=c_steps, interval=100, blit=True) + +# Save or display the animation +ani.save('../temp/PMM.gif', writer='pillow') # Save as a GIF file +plt.show() # Display the animation + +# %%