-
Notifications
You must be signed in to change notification settings - Fork 1
/
reduction_plot.py
81 lines (69 loc) · 1.52 KB
/
reduction_plot.py
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
import plotly.express as px
class DRType:
PCA = 'PCA'
UMAP = 'UMAP'
TSNE = 't-SNE'
def dr_plot_2d(
df,
x,
y,
color_attr,
title,
hover_data,
method
):
fig = px.scatter(
df,
x=x,
y=y,
color=color_attr,
title=title,
hover_data=hover_data
)
if method == DRType.PCA:
fig.update_layout(
xaxis_title="Principle component 1",
yaxis_title="Principle component 2"
)
elif method == DRType.TSNE or method == DRType.UMAP:
fig.update_layout(
xaxis_title="Dimension 1",
yaxis_title="Dimension 2",
)
return fig
def dr_plot_3d(
df,
x,
y,
z,
color_attr,
title,
hover_data,
method
):
fig = px.scatter_3d(
df,
x=x,
y=y,
z=z,
color=color_attr,
title=title,
hover_data=hover_data
)
if method == DRType.PCA:
fig.update_layout(
scene=dict(
xaxis_title="Principle component 1",
yaxis_title="Principle component 2",
zaxis_title="Principle component 3"
)
)
elif method == DRType.TSNE or method == DRType.UMAP:
fig.update_layout(
scene=dict(
xaxis_title="Dimension 1",
yaxis_title="Dimension 2",
zaxis_title="Dimension 3"
)
)
return fig