Hello,
I’m trying to plot a 3d cube inside a 3d cube using plotly.graph_objects.Volume such that:
- The cube’s shape is (3,3,3) and it contains 27 values. It should be parallel to the axes.
- At (1,1,1) there’s a different value, that should be displayed as an inner cube at the center of the bigger cube.
My code is similar to the code at plotly’s website 3d volume plots in Python
Here it is:
import plotly.graph_objects as go
import numpy as np
X, Y, Z = np.mgrid[0:2:3j, 0:2:3j, 0:2:3j]
values = np.ones(X.shape)*0.1
values[1,1,1] = 1
fig = go.Figure(data=go.Volume(
x=X.flatten(),
y=Y.flatten(),
z=Z.flatten(),
value=values.flatten(),
isomin=0.1,
isomax=0.8,
opacity=0.1, # needs to be small to see through all surfaces
surface_count=17, # needs to be a large number for good volume rendering
))
fig.show()
What I get is
And what I’m looking for is something like this:
As you can see, both the shape and the colors are problematic in my first picture. The shape is especially bad. I obtained the second picture using Mesh3d, but this solution doesn’t work well because in my real use I have to define each voxel individually and it results in “walls” like these:
Thanks in advance for your help,
Raz