summaryrefslogtreecommitdiff
path: root/src/python/example/plot_rips_complex.py
diff options
context:
space:
mode:
authorGard Spreemann <gspr@nonempty.org>2020-01-20 09:33:33 +0100
committerGard Spreemann <gspr@nonempty.org>2020-01-20 09:33:33 +0100
commit8c751c3929b1727c1e2e2781259ddaa39cfd8df3 (patch)
tree0e680ea9182032cc82a732230217980ada093ee9 /src/python/example/plot_rips_complex.py
parenta11db9cb0c8b35fa393c95d698754bb0c652b1d6 (diff)
parent9acc59fcc1d5001a212e7b9cd6f00a569a625882 (diff)
Merge branch 'dfsg/latest' into debian/sid
Diffstat (limited to 'src/python/example/plot_rips_complex.py')
-rwxr-xr-xsrc/python/example/plot_rips_complex.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/python/example/plot_rips_complex.py b/src/python/example/plot_rips_complex.py
new file mode 100755
index 00000000..214a3c0a
--- /dev/null
+++ b/src/python/example/plot_rips_complex.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import numpy as np
+import gudhi
+points = np.array(gudhi.read_points_from_off_file('../../data/points/Kl.off'))
+rc = gudhi.RipsComplex(points=points, max_edge_length=.2)
+st = rc.create_simplex_tree(max_dimension=2)
+# We are only going to plot the triangles
+triangles = np.array([s[0] for s in st.get_skeleton(2) if len(s[0])==3])
+
+# First possibility: plotly
+import plotly.graph_objects as go
+fig = go.Figure(data=[
+ go.Mesh3d(
+ # Use the first 3 coordinates, but we could as easily pick others
+ x=points[:,0],
+ y=points[:,1],
+ z=points[:,2],
+ i = triangles[:,0],
+ j = triangles[:,1],
+ k = triangles[:,2],
+ )
+])
+fig.show()
+
+# Second possibility: matplotlib
+from mpl_toolkits.mplot3d import Axes3D
+import matplotlib.pyplot as plt
+fig = plt.figure()
+ax = fig.gca(projection='3d')
+ax.plot_trisurf(points[:,0], points[:,1], points[:,2], triangles=triangles)
+plt.show()
+
+# Third possibility: mayavi
+# (this may take a while)
+from mayavi import mlab
+mlab.triangular_mesh(points[:,0], points[:,1], points[:,2], triangles);
+mlab.show()