Coloring isosurface using another variable

Hello everyone,

I am trying to create three-dimensional isosurfaces using plotly in Python and color it using another variable. However, the isosurfaces are colored by default with the isosurface level instead. I know that one can do something like this using the surfacecolor option for surfaces. Does something similar exist for isosurfaces?

Here’s my code for reference:

isosurfacePlot = go.Isosurface(
            x=Xf,
            y=Yf,
            z=Zf, 
            value=qCrit[:,:,:,i].flatten(),
            isomin=isominVal,
            isomax=isomaxVal
            )

    

    layout3d = dict(title_text='Q-criterion, t = '+str(np.round(timeList[i],2)), title_x=0.5,
            scene_camera_up=dict(x=0, y=1, z=0) 
            )

    
    fig = go.Figure(data=[isosurfacePlot],layout=layout3d)
    fig.update_layout(scene_aspectmode='data') 
    fig.write_image(saveDir+"fig"+str(i+1)+".png")

Hi @vedant ,

does the colorscale parameter help? I am not sure what you actually want to do. Could you provide a reproducible code?

@vedant
A go.Isosurface cannot be colored according to the values of a scalar field defined at its points. As an alternative, you can define the isosurface as a go.Mesh3d, where the triangulation is computed by the algorithm Marching Cubes, implemented by the skimage function measure.marching_cubes_lewiner.

Here is a 5 years old example posted on chart studio: https://chart-studio.plotly.com/~empet/14613. I’ve just updated it to be sure it works with Plotly version 5.+

1 Like

@empet thank you for your response.

@AIMPED I think I was not perfectly clear in my question. My apologies. As @empet mentioned, I want to color my volumetric isosurfaces using another scalar field. I will try out his solution. Thank you for your time.