-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpy_demo.py
100 lines (93 loc) · 2.32 KB
/
numpy_demo.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
from pylab import *
kolory = ['b','g','r','c','m','y','k','w'] + [(r,g,b) for r in arange(0.5,1.,0.1) for g in arange(0.0,0.5,0.1) for b in arange(0.3,0.5,0.1)]
def wykres3D(x,y,z,kolor,labels):
#print x
#print y
#print z
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
#def randrange(n, vmin, vmax):
# return (vmax-vmin)*np.random.rand(n) + vmin
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
distinct = daj_klucze(kolor)
kol_dist = zip(kolory,distinct)
kol_dict = {}
for i in range(len(distinct)):
kol_dict[distinct[i]]=kolory[i]
zbior = zip(x,y,z,kolor)
sety = []
for i in range(len(kol_dist)):
sety.append([z for z in zbior if z[3]==kol_dist[i][1]])
for i in sety:
x = [z[0] for z in i]
y = [z[1] for z in i]
z = [z[2] for z in i]
k1 = kol_dict[i[0][3]]
#for j in kol_dist:
# if(z[3]==j[1]):
# kol = j[0]
# break;
ax.scatter(x,y,z,c=k1,marker='o')
#plot(t, s, color=kol,marker='o',linestyle='None')
## OLD
#n = 100
#for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
# xs = randrange(n, 23, 32)
# ys = randrange(n, 0, 100)
# zs = randrange(n, zl, zh)
# ax.scatter(xs, ys, zs, c=c, marker=m)
## OLD
ax.set_xlabel(labels[0])
ax.set_ylabel(labels[1])
ax.set_zlabel(labels[2])
plt.show()
def daj_klucze(seq):
checked = []
for e in seq:
if e not in checked:
checked.append(e)
return checked
def get_sets(zbior,kol_dist):
zbior
def wykres(t,s,kolor,x_str,y_str):
distinct = daj_klucze(kolor)
kol_dist = zip(kolory,distinct)
zbior = zip(t,s,kolor)
sety = []
kol_dict = {}
for i in range(len(distinct)):
kol_dict[distinct[i]]=kolory[i]
for i in range(len(kol_dist)):
sety.append([z for z in zbior if z[2]==kol_dist[i][1]])
#print sety
for i in sety:
t = [z[0] for z in i]
s = [z[1] for z in i]
k1 = kol_dict[i[0][2]]
#for j in kol_dist:
# if(z[2]==j[1]):
# kol = j[0]
# break;
plot(t, s, color=k1,marker='o',linestyle='None')
xlabel(x_str)
ylabel(y_str)
title('SWD')
grid(True)
show()
def debug2d():
x = range(5)
y = range(5)
cols = [1,5,2,0,0]
labels = ["x","y"]
wykres(x,y,cols,labels[0],labels[1])
def debug3d():
x = range(5)
y = range(5)
z = range(5)
cols = [1,1,1,0,0]
labels = ["x","y","z"]
wykres3D(x,y,z,cols,labels)
if(__name__=="__main__"):
debug3d()