This following is an implementation to generate animation, but not yet working. from matplotlib.animation import FuncAnimation npoints = results_2body.shape[0] x_values = np.concatenate((results_2body[:, [1, 3]])) y_values = np.concatenate((results_2body[:, [2, 4]])) particles = np.array(["1"] * npoints + ["2"] * npoints) # Convert particle labels to numeric values particle_colors = np.where(particles == "1", 0, 1) # Create the figure and axis objects fig, ax = plt.subplots() scat = ax.scatter(x_values, y_values, c=particle_colors, cmap='coolwarm', alpha=0.7, s=100) # Set the axis labels and limits ax.set_xlabel('x') ax.set_ylabel('y') ax.set_xlim(-8, 8) ax.set_ylim(-8, 8) # Update function for the animation def update(frame): start_idx = frame * npoints end_idx = (frame + 1) * npoints scat.set_offsets(np.column_stack([x_values[start_idx:end_idx], y_values[start_idx:end_idx]])) scat.set_array(particle_colors[start_idx:end_idx]) return scat, # Create the animation ani = FuncAnimation(fig, update, frames=results_2body.shape[0] // 2, interval=50) # Save the animation as a GIF ani.save('2-body.gif', writer='pillow', fps=20) plt.show()