I’m trying to render multiple objects using the trisurf function in combination with the marching cubes function (https://plot.ly/python/isosurfaces-with-marching-cubes/#plotly-isosurfaces-defined-as-trisurfs). Ideally I’d like to color each object as separate color. Any suggestions on how to go about this?
Thanks for your help!
Could you add a quick example of creating two separate trisurf figures containing two surfaces that you would like to eventually place in the same figure? I’m not very familiar with the trisurf logic yet, but I’m happy to take a look if you can provide this as a starting point.
Thanks for helping with this. Here is a basic example where I’d like to render two separate spherical objects in the same space, each as a different color.
import plotly import plotly.plotly as py import plotly.graph_objs as go import plotly.figure_factory as ff from skimage.morphology import ball from skimage import measure #ball of size 5 vol = ball(5) vertices, faces, normals, values = measure.marching_cubes(vol, 0) x,y,z = zip(*vertices) fig0 = ff.create_trisurf(x=x,y=y, z=z, plot_edges=False,colormap=[(0.15, 0,0.4), (0.65, 0.12,1)],simplices=faces,title='ball 5') #ball of size 3 padded to the same total size as ball of 5 vol = np.pad(ball(3), 2, 'constant', constant_values=(0)) vertices, faces, normals, values = measure.marching_cubes(vol, 0) x,y,z = zip(*vertices) fig1 = ff.create_trisurf(x=x,y=y, z=z, plot_edges=False,colormap=[(0.15, 0.4,0), (0.65, 1, 0.12)],simplices=faces,title='ball 3') #here's the part that I'm missing -- but something like combination = [fig0,fig1] plotly.offline.plot(combination)
ff.create_trisurf() is the older Plotly method to define trisurfs. It’s one year now since the trisurfs can be generated as
mesh3d traces. Here is an example of isosurface in volumetric data, I posted at that time https://plot.ly/~empet/14613. It works with Plotly 3.3.0, too (I’ve just checked it).
So your issue is now fixed by defining the two trisurfs as
mesh3d traces and your figure as
go.Figure(data=[mesh1, mesh2], layout=layout).
Your intensity function could be the standard oneL
def standard_intensity(x, y, z): return z
i.e the vertex intensity (color) is assigned according to its z-coordinate value.