Dynamically plot the three objectives for a given workload and algorithm for a specific seed.
(workload, algorithm, seed)
| 83 | |
| 84 | |
| 85 | def dynamic_plot(workload, algorithm, seed): |
| 86 | """ |
| 87 | Dynamically plot the three objectives for a given workload and algorithm for a specific seed. |
| 88 | """ |
| 89 | # Collect all data to understand the range |
| 90 | all_data, global_mean, global_std = collect_all_data(workload) |
| 91 | global_min = np.min(all_data, axis=0) |
| 92 | global_max = np.max(all_data, axis=0) |
| 93 | |
| 94 | # Load data for the specific seed |
| 95 | df = load_data(workload, algorithm, seed) |
| 96 | |
| 97 | # Normalize data (Min-Max normalization) |
| 98 | df_normalized = (df[objectives] - global_min) / (global_max - global_min) |
| 99 | |
| 100 | fig = plt.figure() |
| 101 | ax = fig.add_subplot(111, projection='3d') |
| 102 | ax.set_title(f"Dynamic Plot for {workload} - {algorithm} - Seed {seed}") |
| 103 | ax.set_xlabel(objectives[0]) |
| 104 | ax.set_ylabel(objectives[1]) |
| 105 | ax.set_zlabel(objectives[2]) |
| 106 | |
| 107 | # Initialize two scatter plots: one for all previous points, one for the new point |
| 108 | previous_points = ax.scatter([], [], [], c='b', marker='o') # all previous points in blue |
| 109 | current_point = ax.scatter([], [], [], c='r', marker='o') # current point in red |
| 110 | |
| 111 | def init(): |
| 112 | previous_points._offsets3d = ([], [], []) |
| 113 | current_point._offsets3d = ([], [], []) |
| 114 | return previous_points, current_point |
| 115 | |
| 116 | def update(frame): |
| 117 | # Add all previous points up to the current frame |
| 118 | previous_points._offsets3d = (df_normalized.iloc[:frame][objectives[0]].values, |
| 119 | df_normalized.iloc[:frame][objectives[1]].values, |
| 120 | df_normalized.iloc[:frame][objectives[2]].values) |
| 121 | |
| 122 | # Add the current point (latest one in the sequence) |
| 123 | current_point._offsets3d = (df_normalized.iloc[frame:frame+1][objectives[0]].values, |
| 124 | df_normalized.iloc[frame:frame+1][objectives[1]].values, |
| 125 | df_normalized.iloc[frame:frame+1][objectives[2]].values) |
| 126 | return previous_points, current_point |
| 127 | |
| 128 | frames = len(df) |
| 129 | ani = FuncAnimation(fig, update, frames=frames, blit=False, repeat=False) |
| 130 | |
| 131 | # Save the plot to a file |
| 132 | gif_path = package_path / "demo" / "comparison" / "gifs" / f"{target}_{algorithm}_{workload}_{seed}.gif" |
| 133 | ani.save(gif_path, writer='imagemagick') |
| 134 | plt.close(fig) # Close the plot to free memory |
| 135 | |
| 136 | |
| 137 | # def dynamic_plot_html(workload, algorithm, seed): |
| 138 | """ |
| 139 | Dynamically plot the three objectives for a given workload and algorithm for a specific seed using Plotly. |
| 140 | """ |
| 141 | # Collect all data to understand the range |
| 142 | all_data, global_mean, global_std = collect_all_data(workload) |
nothing calls this directly
no test coverage detected