From 00985c119ae164477e8493a69f32f103774cf51c Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 16 Nov 2019 14:05:19 +0100 Subject: Examples for plotting a simplicial complex with plotly / matplotlib --- src/python/example/plot_rips_complex.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 src/python/example/plot_rips_complex.py (limited to 'src/python/example/plot_rips_complex.py') diff --git a/src/python/example/plot_rips_complex.py b/src/python/example/plot_rips_complex.py new file mode 100755 index 00000000..d2637ea8 --- /dev/null +++ b/src/python/example/plot_rips_complex.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import numpy as np +import gudhi +points = np.array(gudhi.read_off('../../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.mlab.triangular_mesh -- cgit v1.2.3 From 71ffd4fcbf273289a556ee5ed39a6b8edf8444a1 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 16 Nov 2019 14:27:52 +0100 Subject: Add mayavi to the examples --- src/python/example/plot_alpha_complex.py | 5 ++++- src/python/example/plot_rips_complex.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/python/example/plot_rips_complex.py') diff --git a/src/python/example/plot_alpha_complex.py b/src/python/example/plot_alpha_complex.py index 98931975..99c18a7c 100755 --- a/src/python/example/plot_alpha_complex.py +++ b/src/python/example/plot_alpha_complex.py @@ -31,4 +31,7 @@ ax = fig.gca(projection='3d') ax.plot_trisurf(points[:,0], points[:,1], points[:,2], triangles=triangles) plt.show() -# Third possibility: mayavi.mlab.triangular_mesh +# Third possibility: mayavi +from mayavi import mlab +mlab.triangular_mesh(points[:,0], points[:,1], points[:,2], triangles); +mlab.show() diff --git a/src/python/example/plot_rips_complex.py b/src/python/example/plot_rips_complex.py index d2637ea8..1c878db1 100755 --- a/src/python/example/plot_rips_complex.py +++ b/src/python/example/plot_rips_complex.py @@ -31,4 +31,8 @@ ax = fig.gca(projection='3d') ax.plot_trisurf(points[:,0], points[:,1], points[:,2], triangles=triangles) plt.show() -# Third possibility: mayavi.mlab.triangular_mesh +# Third possibility: mayavi +# (this may take a while) +from mayavi import mlab +mlab.triangular_mesh(points[:,0], points[:,1], points[:,2], triangles); +mlab.show() -- cgit v1.2.3