-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.py
More file actions
141 lines (127 loc) · 3.23 KB
/
visualization.py
File metadata and controls
141 lines (127 loc) · 3.23 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import matplotlib.lines as mlines
import matplotlib.pyplot as plt
import pandas as pd
# Load data
df = pd.read_csv("maimai.csv")
# Preprocessing
df["Achv"] = df["Achv"].astype(str).str.replace("%", "", regex=False)
df["Achv"] = pd.to_numeric(df["Achv"], errors="coerce")
df["Chart Constant"] = pd.to_numeric(df["Chart Constant"], errors="coerce")
df = df.dropna(subset=["Achv", "Chart Constant", "Difficulty"])
# Filter and format
df["Difficulty"] = df["Difficulty"].str.title()
target_difficulties = ["Advanced", "Expert", "Master"]
df = df[df["Difficulty"].isin(target_difficulties)]
# Calculate median trend
median_trend = (
df.groupby("Chart Constant")["Achv"]
.median()
.reset_index()
.sort_values("Chart Constant")
)
# Configuration
COLORS = {
"Background": "#F3F3EE",
"Text": "#13343B",
"Advanced": "#1FB8CD",
"Expert": "#DB4545",
"Master": "#2E8B57",
"Grid": "#D3D3D3",
}
MARKERS = {"Advanced": "s", "Expert": "^", "Master": "d"}
# Plotting
fig, ax = plt.subplots(figsize=(14, 9))
fig.patch.set_facecolor(COLORS["Background"])
ax.set_facecolor(COLORS["Background"])
# Scatter plots
for diff in target_difficulties:
subset = df[df["Difficulty"] == diff]
ax.scatter(
subset["Chart Constant"],
subset["Achv"],
c=COLORS[diff],
marker=MARKERS[diff],
s=25,
label=diff,
edgecolor="none",
alpha=0.9,
zorder=3,
)
# Median line
ax.plot(
median_trend["Chart Constant"],
median_trend["Achv"],
color="black",
linestyle=":",
linewidth=2,
label="Median Achv by Chart Constant",
zorder=4,
)
# Styling
ax.grid(True, which="major", axis="both", color=COLORS["Grid"], alpha=0.6, zorder=0)
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_color(COLORS["Grid"])
ax.spines["bottom"].set_color(COLORS["Grid"])
ax.set_title(
"Achv vs Chart Constant by Difficulty",
fontsize=24,
fontweight="bold",
color=COLORS["Text"],
pad=40,
)
ax.set_xlabel("Chart Constant", fontsize=16, color=COLORS["Text"], labelpad=20)
ax.set_ylabel("Achv (%)", fontsize=16, color=COLORS["Text"], labelpad=20)
ax.tick_params(axis="both", colors="#555555", labelsize=12)
# Legend
legend_handles = [
mlines.Line2D(
[],
[],
color=COLORS["Advanced"],
marker=MARKERS["Advanced"],
linestyle="None",
markersize=8,
label="Advanced",
),
mlines.Line2D(
[],
[],
color=COLORS["Expert"],
marker=MARKERS["Expert"],
linestyle="None",
markersize=8,
label="Expert",
),
mlines.Line2D(
[],
[],
color=COLORS["Master"],
marker=MARKERS["Master"],
linestyle="None",
markersize=8,
label="Master",
),
mlines.Line2D(
[],
[],
color="black",
linestyle=":",
linewidth=2,
label="Median Achv by Chart Constant",
),
]
legend = ax.legend(
handles=legend_handles,
loc="upper center",
bbox_to_anchor=(0.5, 1.08),
ncol=4,
frameon=False,
fontsize=13,
)
plt.setp(legend.get_texts(), color="#333333")
# Limits
ax.set_ylim(65, 102)
ax.set_xlim(6.5, 13.8)
plt.tight_layout()
plt.show()