get ploty.graph_objects.Volume to only show the surface of the Volume

Question:

I am using plotly to plot some simple Volumes, like in the code below.

import plotly.graph_objects as go
import numpy as np


X, Y, Z = np.mgrid[-3:3:10j, -5:5:10j, -1:1:3j]
values = np.random.randint(100, size=300)

fig = go.Figure(go.Volume(x=X.flatten(),
                          y=Y.flatten(),
                          z=Z.flatten(),
                          value=values.flatten(),
                          opacity=1,
                          surface_count=21))
fig.show()

This results in the following plot.

enter image description here

Is there a way to make the volumes fully intransparent/opaque? I want the boxes to get completly opaque, so I am only seeing the surface of the boxes plotted in the example image and not seeing any internals of the box plotted.

Asked By: Chris7opher

||

Answers:

You can use go.Isosurface, if you want to get opaque volume.

import plotly.graph_objects as go
import numpy as np


X, Y, Z = np.mgrid[-3:3:10j, -5:5:10j, -1:1:3j]
values = np.random.randint(100, size=300)

fig = go.Figure(data=[go.Isosurface(
    x=X.flatten(),
    y=Y.flatten(),
    z=Z.flatten(),
    value=values.flatten(),
    showscale=False,
    colorscale='earth',
)])


fig.show()

Output:

enter image description here

Answered By: Hamzah