-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatter.py
More file actions
74 lines (60 loc) · 1.53 KB
/
scatter.py
File metadata and controls
74 lines (60 loc) · 1.53 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
import matplotlib.pyplot as plt
import numpy as np
def plot_rank_scatter(
labels,
x_values,
y_values,
corr_value=None,
save_path=None,
xlabel="Score (X)",
ylabel="Score (Y)",
value_range=(1, 5),
tick_step=1.0,
figsize=(3.2, 3.2),
):
"""
Generic rank-consistency scatter plot.
"""
markers = ["o", "s", "^", "D", "v", ">", "<", "p"]
colors = plt.cm.tab10.colors
vmin, vmax = value_range
plt.figure(figsize=figsize)
for i, label in enumerate(labels):
plt.scatter(
x_values[i],
y_values[i],
marker=markers[i % len(markers)],
color=colors[i % len(colors)],
s=45,
edgecolors="black",
linewidths=0.5,
label=label,
)
# y = x reference line
plt.plot(
[vmin, vmax],
[vmin, vmax],
linestyle="--",
linewidth=1,
color="black",
)
plt.xlabel(xlabel, fontsize=9)
plt.ylabel(ylabel, fontsize=9)
plt.xlim(vmin, vmax)
plt.ylim(vmin, vmax)
ticks = np.arange(vmin, vmax + 1e-6, tick_step)
plt.xticks(ticks)
plt.yticks(ticks)
if corr_value is not None:
plt.title(f"Spearman $\\rho$ = {corr_value:.2f}", fontsize=9)
plt.legend(
fontsize=7,
frameon=False,
loc="lower right",
handletextpad=0.3,
borderaxespad=0.3,
)
plt.tight_layout()
if save_path is not None:
plt.savefig(save_path, format="pdf", bbox_inches="tight")
plt.close()