Spaces:
Runtime error
Runtime error
File size: 2,022 Bytes
2a33798 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import pandas as pd
import matplotlib.pyplot as plt
# Load the CSV data
data = pd.read_csv("performance_data.csv")
# Group games by type
game_types = {
"Classic Control": ["Acrobot-v1", "CartPole-v0", "MountainCar-v0"],
"Box 2D": ["LunarLander-v2"],
"Toy Text": ["Taxi-v3", "CliffWalking-v0", "Blackjack-v1"]
}
for game_type, games in game_types.items():
fig, axs = plt.subplots(1, len(games), figsize=(12 * len(games), 6))
fig.suptitle(f"Performance Plot: {game_type}", fontsize=28, fontname="Times New Roman")
if len(games) == 1:
axs = [axs]
handles, labels = [], []
for idx, game in enumerate(games):
# Filter data to get information for the current game (in the loop)
game_data = data[data["game"] == game]
axs[idx].set_title(game, fontsize=20, fontname="Times New Roman")
axs[idx].set_xlabel("Levels", fontsize=16, fontname="Times New Roman")
if idx == 0:
axs[idx].set_ylabel("Scores", fontsize=16, fontname="Times New Roman")
for index, row in game_data.iterrows():
decider_name = row["decider_name"]
levels = ["l1", "l2", "l3", "l4", "l5"]
scores = row[levels].values.tolist()
lines = axs[idx].plot(levels, scores, "-o", label=decider_name)
# Grab the handle and label for creating a global legend
handles.append(lines[0])
labels.append(decider_name)
# Eliminate duplicate labels and handles
unique_labels = []
unique_handles = []
for handle, label in zip(handles, labels):
if label not in unique_labels:
unique_labels.append(label)
unique_handles.append(handle)
# Add a legend at the bottom middle of the figure
fig.legend(
unique_handles,
unique_labels,
loc="lower center",
ncol=4, prop={'size': 18}
)
# Adjust layout to accommodate the legend and prevent cropping
plt.savefig("./vis/" + game_type + ".png", dpi=300)
|