-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualization.py
156 lines (126 loc) · 5.03 KB
/
visualization.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import os
import networkx as nx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
from math import pi
def transaction_graph(file_path:str):
return
def database_visualization(file_path:str):
df = pd.read_csv(file_path)
print(df["category"].value_counts)
return
def radar_graph(file_path:str):
# Set data
# Type,Name,Balance_sum,Balance_mean,DAU_sum,DAU_mean,Vol_sum,Vol_mean,Total_rank_sum,Total_rank_mean,Txs_sum,Txs_mean
df = pd.read_csv(file_path)
df = df[['Name', 'Balance_mean', 'DAU_mean', 'Vol_mean', 'Total_rank_mean', 'Txs_mean']][0:2]
# df = pd.DataFrame({
# 'group': ['A','B','C','D'],
# 'Transaction': [38, 1.5, 30, 4],
# 'Volumn': [29, 10, 9, 34],
# 'Balance': [8, 39, 23, 24],
# 'var4': [7, 31, 33, 14],
# 'var5': [28, 15, 32, 14]
# })
# ------- PART 1: Create background
# number of variable
categories=list(df)[1:]
N = len(categories)
# What will be the angle of each axis in the plot? (we divide the plot / number of variable)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]
# Initialise the spider plot
ax = plt.subplot(111, polar=True)
# If you want the first axis to be on top:
ax.set_theta_offset(pi / 2)
ax.set_theta_direction(-1)
# Draw one axe per variable + add labels labels yet
plt.xticks(angles[:-1], categories)
# Draw ylabels
ax.set_rlabel_position(0)
plt.yticks([1000,2000,3000], ["1000","2000","3000"], color="grey", size=7)
plt.ylim(0,3500)
# ------- PART 2: Add plots
# Plot each individual = each line of the data
# I don't do a loop, because plotting more than 3 groups makes the chart unreadable
# Ind1
values=df.loc[0].drop('Name').values.flatten().tolist()
values += values[:1]
ax.plot(angles, values, linewidth=1, linestyle='solid', label="group A")
ax.fill(angles, values, 'b', alpha=0.1)
# Ind2
values=df.loc[1].drop('Name').values.flatten().tolist()
values += values[:1]
ax.plot(angles, values, linewidth=1, linestyle='solid', label="group B")
ax.fill(angles, values, 'r', alpha=0.1)
# Add legend
plt.legend(loc='upper right', bbox_to_anchor=(0.1, 0.1))
plt.show()
def plot_3d_multifile(path:str, columns:list, columns_name:list):
fig = plt.figure()
ax = Axes3D(fig)
cmap = ['spring', 'summer', 'autumn', 'winter']
colors = ['red', 'yellow', 'blue', 'green']
files = os.listdir(path)
for i in range(0,len(files)):
nparray = np.load(path + files[i])
length = len(nparray)
nparray = nparray[:,columns]
cm = plt.get_cmap(cmap[i])
col = [cm(float(i)/(26)) for i in range(length)]
X = nparray[:,[0]].flatten()
Y = nparray[:,[1]].flatten()
Z = nparray[:,[2]].flatten()
X = list(map(float, X))
Y = list(map(float, Y))
Z = list(map(float, Z))
# Plot Scatter
#ax.scatter(X, Y, Z, c = col)
ax.scatter(X, Y, Z, c = colors[i])
# Set Legend
# ax.legend(loc='best')
# Set Axis
ax.set_xlabel(columns_name[0])
ax.set_ylabel(columns_name[1])
ax.set_zlabel(columns_name[2])
plt.title(path)
plt.show()
def plot_3d_single(path:str, columns:list):
df = pd.read_csv(path)
if 'tron' in path:
df_game = df.loc[df['Name']=='_game',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
df_highrisk = df.loc[df['Name']=='_highrisk',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
df_exchange = df.loc[df['Name']=='_exchange',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
df_gamble = df.loc[df['Name']=='_gamble',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
else:
df_game = df.loc[df['Name']=='game',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
df_highrisk = df.loc[df['Name']=='highrisk',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
df_exchange = df.loc[df['Name']=='exchange',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
df_gamble = df.loc[df['Name']=='gamble',['Balance', 'DAU', 'Vol', 'Txs', 'Name']]
fig = plt.figure()
ax = Axes3D(fig)
cmap = ['spring', 'summer', 'autumn', 'winter']
colors = ['red', 'yellow', 'blue', 'green']
df_list = [df_game, df_highrisk, df_exchange, df_gamble]
i = 0
for item in df_list:
X = item.Txs.values
Y = item.Balance.values
Z = item.DAU.values
ax.scatter(X, Y, Z, c = colors[i])
i+=1
ax.set_xlabel("Txs")
ax.set_ylabel("Balance")
ax.set_zlabel("DAU")
plt.title(path)
plt.show()
if __name__ == '__main__':
# plot_3d_multifile('./feature_data/eth/std/', [1,2,3], ['AUC', 'Peak', 'Var'])
# plot_3d_multifile('./avg_data/eth/', [1,2,3], ['DAU', 'Balance', 'Txs'])
# plot_3d_single('./cate_data/trone_w/tron_all_raw.csv', [])
# transaction_graph('./transaction/cryptokitties_auction.csv')
# radar_graph('./top15_data/game.csv')
database_visualization("./contract_db/database.csv")