-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
281 lines (239 loc) · 8.12 KB
/
main.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Inspired from
# https://towardsdatascience.com/the-art-of-effective-visualization-of-multi-dimensional-data-6c7202990c57
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib as mpl
import numpy as np
import seaborn as sns
import datetime
file_name = "tdata.xlsx"
clist = ['blue', 'green', 'red', 'yellow', 'cyan', 'magenta', 'purple', 'orange', 'khaki', '#4d847f','#83844d', '#844d4d', '#4d8453', '#4d5384',]
mlist = ['o','v','s','P','D','*','X','p','<','>','h','H']
ndata = pd.read_excel(file_name) #sudo pip install xlrd
pd.set_option('display.width', 250)
print "\t\tPLOTTING 10 NUMERICAL ATTRIBUTES AT A TIME"
print "\tDon't forget to change the file_name in the source code. Current file_name is \""+file_name+"\""
print "\tDon't forget to save the generated images"
print "\tAll the legends will be saved in a file called legends.txt"
dtstring = str(datetime.datetime.now()).replace('.',':')
file = open("legends.txt",'a')
file.write("Test conducted on: "+dtstring+"\n")
ndata = ndata.sample(frac=1, random_state=42).reset_index(drop=True)
# ndata = ndata[:400]
print "Description of the dataset in "+file_name+" is as follows:"
print ndata.describe(percentiles = [0.10, 0.25, 0.50, 0.75, 0.90])
print "\nSome top values of dataset are as follows:"
print ndata.head()
# print len(ndata)
# raw_input()
################################## Dimension build up STARTS ######################################
print "\tAll the values are case sensitive"
xaxis = raw_input('Enter x-axis attribute name: ')
file.write("X-axis = '"+xaxis+"' attribute\n")
yaxis = raw_input('Enter y-axis attribute name: ')
file.write("Y-axis = '"+yaxis+"' attribute\n")
zaxis = raw_input('Enter z-axis attribute name: ')
file.write("Z-axis = '"+zaxis+"' attribute\n")
xs = list(ndata[xaxis])
ys = list(ndata[yaxis])
zs = list(ndata[zaxis])
data_points = [(x, y, z) for x, y, z in zip(xs, ys, zs)]
# ----- ------ ------ ------ ------ ------ ------ ------
facet = raw_input('Enter facet attribute: ')
lcut = [ndata[facet].min()]
cuts = int(raw_input('\t\tHow many cuts do you want? '))
ch = raw_input('\t\tEnter boundary values manually or automatically (m/a)? ')
if 'a' in ch:
lcut = [0.0]
k=0
while k<cuts:
lcut.append(1.0/cuts + lcut[len(lcut)-1])
k+=1
lcut = list(ndata[facet].quantile(lcut))
else:
lcut = [0.0]
if cuts>1:
print "Enter "+str(cuts-1)+" values for cutting"
k=0
while k<cuts-1:
lcut.append(float(raw_input('\t\tEnter value'+str(k+1)+': ')))
k+=1
lcut.append(ndata[facet].max())
lcut[-1] = lcut[-1] + 0.001
if 'a' in ch:
ch = "automatically"
else:
ch = "manually"
file.write("There will be "+str(cuts)+" diagrams containing all the boundary values of '"+facet+"' attribute generated "+ch+"\n")
# ----- ------ ------ ------ ------ ------ ------ ------
sz = raw_input('\nEnter attribute for size of the point: ')
scut = int(raw_input('\t\tEnter number of categories you want in size of the point: '))
ml = [0.0]
ch = raw_input('\t\tEnter boundary values manually or automatically (m/a)? ')
if 'a' in ch:
k=0
while k<scut:
ml.append(1.0/scut + ml[len(ml)-1])
k+=1
ml = ml[1:]
ml = list(ndata[sz].quantile(ml))
else:
k=0
ml = []
while k<scut-1:
ml.append(float(raw_input('\t\tEnter categories boundary '+str(k+1)+': ')))
k+=1
ss = []
for x in list(ndata[sz]):
k=0
while k<len(ml):
if x <= ml[k]:
ss.append(10+((k+1)*2 -1)*10)
break
k+=1
if 'a' in ch:
ch = "automatically"
else:
ch = "manually"
file.write("Size of the points depends on '"+sz+"' attribute "+ch+"\n")
k=0
while k<len(ml):
file.write("\tIf "+sz+".value() < "+str(ml[k])+"\tthen\tPoint size = "+str(10+((k+1)*2 -1)*10)+"\n")
k+=1
# ----- ------ ------ ------ ------ ------ ------ ------
sz = raw_input('\nEnter attribute for color of the point: ')
scut = int(raw_input('\t\tEnter number of categories you want in color of the point: '))
ml = [0.0]
ch = raw_input('\t\tEnter boundary values manually or automatically (m/a)? ')
if 'a' in ch:
k=0
while k<scut:
ml.append(1.0/scut + ml[len(ml)-1])
k+=1
ml = ml[1:]
ml = list(ndata[sz].quantile(ml))
else:
k=0
ml = []
while k<scut-1:
ml.append(float(raw_input('\t\tEnter categories boundary '+str(k+1)+': ')))
k+=1
colors = []
for x in list(ndata[sz]):
k=0
while k<len(ml):
if x <= ml[k]:
colors.append(clist[k])
break
k+=1
if 'a' in ch:
ch = "automatically"
else:
ch = "manually"
file.write("Color of the points depends on '"+sz+"' attribute "+ch+"\n")
k=0
while k<len(ml):
file.write("\tIf "+sz+".value() < "+str(ml[k])+"\tthen\tPoint color = "+clist[k]+"\n")
k+=1
# ----- ------ ------ ------ ------ ------ ------ ------
sz = raw_input('\nEnter attribute for color of the point edge:')
scut = int(raw_input('\t\tEnter number of categories you want in color of the point edge: '))
clist.reverse()
ml = [0.0]
ch = raw_input('\t\tEnter boundary values manually or automatically (m/a)? ')
if 'a' in ch:
k=0
while k<scut:
ml.append(1.0/scut + ml[len(ml)-1])
k+=1
ml = ml[1:]
ml = list(ndata[sz].quantile(ml))
else:
k=0
ml = []
while k<scut-1:
ml.append(float(raw_input('\t\tEnter categories boundary '+str(k+1)+': ')))
k+=1
ec = []
for x in list(ndata[sz]):
k=0
while k<len(ml):
if x <= ml[k]:
ec.append(clist[k])
break
k+=1
if 'a' in ch:
ch = "automatically"
else:
ch = "manually"
file.write("Color of the point edge depends on '"+sz+"' attribute "+ch+"\n")
k=0
while k<len(ml):
file.write("\tIf "+sz+".value() < "+str(ml[k])+"\tthen\tcolor of the point edge = "+clist[k]+"\n")
k+=1
# ----- ------ ------ ------ ------ ------ ------ ------
sz = raw_input('\nEnter attribute for marker of the point: ')
scut = int(raw_input('\t\tEnter number of categories you want in marker of the point: '))
ml = [0.0]
ch = raw_input('\t\tEnter boundary values manually or automatically (m/a)? ')
if 'a' in ch:
k=0
while k<scut:
ml.append(1.0/scut + ml[len(ml)-1])
k+=1
ml = ml[1:]
ml = list(ndata[sz].quantile(ml))
else:
k=0
ml = []
while k<scut-1:
ml.append(float(raw_input('\t\tEnter categories boundary '+str(k+1)+': ')))
k+=1
markers = []
for x in list(ndata[sz]):
k=0
while k<len(ml):
if x <= ml[k]:
markers.append(mlist[k])
break
k+=1
if 'a' in ch:
ch = "automatically"
else:
ch = "manually"
file.write("Marker of the point depends on '"+sz+"' attribute generated "+ch+"\n")
k=0
while k<len(ml):
file.write("\tIf "+sz+".value() < "+str(ml[k])+"\tthen\tmarker of the point = "+mlist[k]+"\n")
k+=1
file.write("\tRefer to https://matplotlib.org/api/markers_api.html#module-matplotlib.markers to see markers and their respective symbols\n")
# ----- ------ ------ ------ ------ ------ ------ ------
sz = raw_input('\nEnter attribute for opacity of the point: ')
opaqlist = list(ndata[sz]/ndata[sz].max())
file.write("Opacity of the point depends on '"+sz+"' attribute. All the values are scaled between 0 (transparent) to 1 (opaque) by dividing all by the MAX value\n")
# ----- ------ ------ ------ ------ ------ ------ ------
sz = raw_input('\nEnter attribute for width of the point edge: ')
lwl = list(1*(0.7 + ndata[sz]/ndata[sz].max())) # 1.4*( 1 + {0 ... 1} )
file.write("Width of the point edge depends on '"+sz+"' attribute. All the values are scaled between 0.7 to 1.5\n\tRefer to the source code to see the formula.\n")
################################## Dimension build up ENDS ######################################
print "\n\nWait.. Plotting..."
ptr = 1
while ptr <= cuts:
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
k=0
for data, color, size, mark, op, lw, e, f in zip(data_points, colors, ss, markers, opaqlist, lwl, ec, list(ndata[facet])):
x, y, z = data
if f >= lcut[ptr-1] and f<lcut[ptr]:
ax.scatter(x, y, z, alpha=op, c=color, edgecolors=e, s=size, marker=mark, linewidths=lw)
k+=1
t = fig.suptitle("Diagram "+str(ptr)+"\n"+str(lcut[ptr-1])+" <= "+facet+" < "+str(lcut[ptr])+"\n"+str(k)+" points\nGenerated on "+dtstring, fontsize=12)
ax.set_xlabel(xaxis)
ax.set_ylabel(yaxis)
ax.set_zlabel(zaxis)
ax.legend()
ptr+=1
file.write("\n\t\tImages generated successfully!\n===================================================================\n\n")
file.close()
plt.show()