Updated the plot_positions method: def plot_positions(self): """Plot the positions of the particles over the iterations""" fig, axs = plt.subplots(len(self.all_positions), 1, figsize=(10, 5*len(self.all_positions))) for i, positions in enumerate(self.all_positions): # Plot the particles' positions at the current iteration axs[i].scatter(positions[:, 0], positions[:, 1], c='b', alpha=0.5) # Plot the goal position axs[i].scatter([-2.2], [4.3], c='g', marker='s', s=100, label='Goal') # Set plot title and labels axs[i].set_title(f'Iteration {i}') axs[i].set_xlabel('X') axs[i].set_ylabel('Y') axs[i].legend() plt.tight_layout() plt.show() # Save the plot to a BytesIO object buf = BytesIO() plt.savefig(buf, format='png') buf.seek(0) image = Image.open(buf) plt.close() return image
verified