-
Notifications
You must be signed in to change notification settings - Fork 6
/
vis_shere.py
82 lines (65 loc) · 2.06 KB
/
vis_shere.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
82
"""
Visualize the features on a sphere
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import scipy.io as sio
import matplotlib
def main(pth):
radius = 1
u = np.linspace(0, 2*np.pi, 20)
v = np.linspace(0, np.pi, 20)
x = radius * np.outer(np.sin(u), np.sin(v))
y = radius * np.outer(np.sin(u), np.cos(v))
z = radius * np.outer(np.cos(u), np.ones_like(v))
# plt.style.use('dark_background')
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(x, y, z, color='black', linewidths = 0.3)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
# ax.set_aspect("equal")
ax.set_box_aspect([1,1,1])
ax.set_xticks([-1, 0, 1])
ax.set_yticks([-1, 0, 1])
ax.set_zticks([-1, 0, 1])
plt.axis('off')
plt.figure(dpi=3000)
data = sio.loadmat(pth)
embeds = data['embeds']
labels = data['labels']
preds = data['preds']
# For better visualization, i.e. the change of color will be more clear by cutting the upper and down
value =preds
upper = np.percentile(value, 90)
upper = np.where(value<upper)[0]
value = value[upper]
embeds = embeds[upper]
down = np.percentile(value, 10)
down = np.where(value>down)[0]
value = value[down]
embeds = embeds[down]
xs = embeds[:,0]
ys = embeds[:,1]
zs = embeds[:,2]
cmapper = matplotlib.cm.get_cmap('magma_r')
sphere = ax.scatter(xs, ys, zs, c = value, cmap= 'brg', vmin=np.min(value), vmax=np.max(value))
for i in range(xs.size):
ax.plot([0, xs[i]], [0, ys[i]], [0, zs[i]], color = 'lightgrey')
fig.colorbar(sphere, fraction=0.02)
plt.show()
# for angle in range(0, 360):
# ax.view_init(30, angle)
# plt.draw()
# plt.pause(.001)
if __name__ == "__main__":
"""
Select one to visualization
"""
# pth = 'regression.mat'
# pth = 'regression+OrdinalEntropy.mat'
# pth = 'classification.mat'
pth = 'regression+Ld_Prime.mat'
main(pth)