People regularly ask how to visualize a simplicial complex, I think we should update the tutorial to show some ways to plot. As examples with 2 different libraries, first alpha complex
import numpy as np
import gudhi
ac = gudhi.AlphaComplex(off_file='/home/glisse/repos/gudhi/data/points/tore3D_1307.off')
st = ac.create_simplex_tree()
triangles = np.array([s[0] for s in st.get_skeleton(2) if len(s[0])==3 and s[1] <= .1])
points = np.array([ac.get_point(i) for i in range(st.num_vertices())])
import plotly.graph_objects as go
fig = go.Figure(data=[
go.Mesh3d(
x=points[:,0],
y=points[:,1],
z=points[:,2],
i = triangles[:,0],
j = triangles[:,1],
k = triangles[:,2],
)
])
fig.show()
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()
and Rips complex (we could pick different coordinates than the first 3 for the projection, possibly multiply by a 5x3 matrix)
import numpy as np
import gudhi
points = np.array(gudhi.read_off('/home/glisse/repos/gudhi/data/points/Kl.off'))
rc = gudhi.RipsComplex(points=points,max_edge_length=.2)
st = rc.create_simplex_tree(max_dimension=2)
triangles = np.array([s[0] for s in st.get_skeleton(2) if len(s[0])==3])
import plotly.graph_objects as go
fig = go.Figure(data=[
go.Mesh3d(
x=points[:,0],
y=points[:,1],
z=points[:,2],
i = triangles[:,0],
j = triangles[:,1],
k = triangles[:,2],
)
])
fig.show()
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()
People regularly ask how to visualize a simplicial complex, I think we should update the tutorial to show some ways to plot. As examples with 2 different libraries, first alpha complex
and Rips complex (we could pick different coordinates than the first 3 for the projection, possibly multiply by a 5x3 matrix)