Revisão | de06c9b275e739903408086766aa49ed03a22294 (tree) |
---|---|
Hora | 2016-04-14 22:01:29 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
Another code to deal with the plotting of a complex hull.
@@ -0,0 +1,92 @@ | ||
1 | +#! /usr/bin/env python | |
2 | + | |
3 | + | |
4 | +import numpy as np | |
5 | +import pylab as pl | |
6 | +import scipy as sp | |
7 | +from scipy.spatial import ConvexHull | |
8 | +from scipy.spatial.distance import euclidean | |
9 | +import matplotlib.pyplot as plt | |
10 | +import mpl_toolkits.mplot3d as a3 | |
11 | + | |
12 | + | |
13 | +cluster_agglomerate=np.array([[ 0.14513811, -0.18930948, -1.44428171], | |
14 | + [ 0.88042945, 1.67057596, -1.45742688], | |
15 | + [-1.66682741, -0.99554261, -1.70267889], | |
16 | + [-0.95535694, 2.3159907 , -1.93637881], | |
17 | + [ 1.09396798, 1.7987614 , -3.44524095], | |
18 | + [-2.63620654, 0.16588691, -3.02436539], | |
19 | + [ 0.19027056, 2.70740725, 0.11479029], | |
20 | + [ 2.77638842, 1.70535678, -2.10208878], | |
21 | + [-0.09149779, -0.81908733, 2.07425244], | |
22 | + [-0.48408772, 0.96793567, 1.26652603], | |
23 | + [ 0.67499278, -2.5386008 , 1.39914827], | |
24 | + [ 1.02571108, -1.60932884, -0.34500693], | |
25 | + [ 2.78789155, -1.42050584, 0.59682802], | |
26 | + [-0.14688239, -2.36883246, 3.35177362], | |
27 | + [-1.71507089, 0.19184887, 2.68408562], | |
28 | + [-1.87886026, -1.58255618, 3.97006406], | |
29 | + [ 6.61540229, 1.98324725, 0.82767368], | |
30 | + [ 7.46818823, 3.00950487, -0.66214223], | |
31 | + [ 4.80777628, 1.97159273, 1.68344958], | |
32 | + [ 6.3548727 , 2.26459561, 2.92819854], | |
33 | + [ 4.70026626, 0.44618044, 0.3866837 ], | |
34 | + [ 3.44366671, 1.87939977, -0.2203051 ], | |
35 | + [ 2.92460648, 1.98510457, 2.37510769], | |
36 | + [ 5.07053866, -0.10349542, -1.51041234], | |
37 | + [ 7.21643437, -1.32050186, -0.70707322], | |
38 | + [ 6.93292243, 0.58458074, -1.2458508 ], | |
39 | + [ 7.84238244, -2.97562362, -1.63914669], | |
40 | + [ 7.43212373, 0.10620418, 0.68315389], | |
41 | + [ 9.59692827, -2.0843759 , -1.26623658], | |
42 | + [ 8.34540867, -1.14927294, 1.95073173], | |
43 | + [ 6.57425162, -2.13797392, -2.94804639], | |
44 | + [ 6.93340304, -4.4591665 , -0.63578546]]) | |
45 | + | |
46 | + | |
47 | + | |
48 | +# see http://bit.ly/1qJlWkP | |
49 | + | |
50 | + | |
51 | + | |
52 | +# Generate random points & convex hull | |
53 | +points = cluster_agglomerate # np.random.rand(20,3) | |
54 | +print "points are, ", points | |
55 | +hull = ConvexHull(points) | |
56 | +print "I calculated the convex hull" | |
57 | + | |
58 | +# either this, or the alternative after the comments | |
59 | + | |
60 | +# ax = a3.Axes3D(pl.figure()) | |
61 | +# facetCol = [0, 1, 0.0] | |
62 | + | |
63 | +# ax.plot_trisurf(points[:,0], points[:,1], points[:,2], | |
64 | +# triangles=hull.simplices) | |
65 | + | |
66 | + | |
67 | +# ax.scatter(points[:,0], points[:,1], points[:,2], s=6000) | |
68 | + | |
69 | +# plt.axis('off') | |
70 | +# plt.show() | |
71 | + | |
72 | + | |
73 | + | |
74 | + | |
75 | +ax = a3.Axes3D(pl.figure()) | |
76 | +facetCol = sp.rand(3) #[0.0, 1.0, 0.0] | |
77 | + | |
78 | + | |
79 | +for simplex in hull.simplices: | |
80 | + vtx = [points[simplex[0],:], points[simplex[1],:], points[simplex[2],:]] | |
81 | + tri = a3.art3d.Poly3DCollection([vtx], linewidths = 2, alpha = 0.5) | |
82 | + tri.set_color(facetCol) | |
83 | + tri.set_edgecolor('k') | |
84 | + ax.add_collection3d(tri) | |
85 | + | |
86 | +ax.scatter(points[:,0], points[:,1], points[:,2], s=6000) | |
87 | + | |
88 | + | |
89 | +plt.axis('off') | |
90 | +plt.show() | |
91 | + | |
92 | +print "So far so good" |