summaryrefslogtreecommitdiff
path: root/src/python/example
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2019-11-16 15:11:06 +0100
committerMarc Glisse <marc.glisse@inria.fr>2019-11-16 15:11:06 +0100
commit7880c08d7ff7c42d7b089f9d1252c85289bf7596 (patch)
treec91b1c9785f8ef8d50f150b69dd4648aa5ca20b6 /src/python/example
parent71ffd4fcbf273289a556ee5ed39a6b8edf8444a1 (diff)
Example plot of triangles, edges and vertices with mayavi
Diffstat (limited to 'src/python/example')
-rwxr-xr-xsrc/python/example/plot_simplex_tree_dim012.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/python/example/plot_simplex_tree_dim012.py b/src/python/example/plot_simplex_tree_dim012.py
new file mode 100755
index 00000000..e6a1a4e0
--- /dev/null
+++ b/src/python/example/plot_simplex_tree_dim012.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+import numpy as np
+import gudhi
+
+# Coordinates of the points
+points=np.array([[0,0,0],[1,0,0],[0,1,0],[0,0,1],[1,1,1],[1,1,0],[0,1,1]])
+# Build the simplicial complex with a tetrahedon, an edge and an isolated vertex
+cplx=gudhi.SimplexTree()
+cplx.insert([1,2,3,5])
+cplx.insert([4,6])
+cplx.insert([0])
+
+from mayavi import mlab
+# Plot triangles
+triangles = np.array([s[0] for s in cplx.get_skeleton(2) if len(s[0])==3])
+mlab.triangular_mesh(points[:,0], points[:,1], points[:,2], triangles);
+# Plot edges
+for s in cplx.get_skeleton(1):
+ e = s[0]
+ if len(e) == 2:
+ pts = points[[e[0],e[1]]]
+ mlab.plot3d(pts[:,0],pts[:,1],pts[:,2],tube_radius=None)
+# Plot points
+mlab.points3d(points[:,0], points[:,1], points[:,2])
+mlab.show()