Full filled sides of a volume with give corner nodes

Hi

I have corner points of a volume and I want to draw this volume with all surfaces filled. I wrote the below code but Unfortunately as you see it’s all side surfaces do not fill. What should I do? (please guide me on python plotly and I can’t use dash)

The reason of add traces is to active other surfaceaxis and that would be great if only with one trace I could add it.

import plotly.graph_objects as go
import numpy as np
from numpy import pi, sin, cos

x= [0,1,0,0,0,1,0,0]
y= [0,0,1,0,0,0,1,0]
z= [0,0,0,0,1,1,1,1]


linemode={'width': 5, 'color': 'black'}
fig = go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=1,surfacecolor='purple', marker_size=3,line=linemode))
fig.add_scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=2,surfacecolor='purple', marker_size=3,line=linemode)
fig.add_scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=0,surfacecolor='purple', marker_size=3,line=linemode)

fig.show()

image

@Bijan
It doesn’t fill the upper surface, because you passed to each scatter3d the same x, y, z lists. Usually you must give only the coordinates of 3D points that define that surface/plane parallel with the planes of coordinates (i.e. planes of equation x=0, y=0, z=0). You have two surfaces parallel to z=0, and Plotly doesn’t fill simultaneously two parallel planes. You must give data for each one.
To fill the unfilled surface in your plot, just
add this line of code:

fig.add_scatter3d(x=[0,1, 0],  y=[0, 0, 1],  z=[1,1,1], 
                              surfaceaxis=2, surfacecolor='purple',
                             marker_size=3, line=linemode)
1 Like

@empet

I did what you said and I got the below image. But what should I do if I want to fill also sides? Because I want to get a volume and for this purpose I need to have surfaces also in sides. Is there any way or I the only way is according our discussion in ( Draw a 3d object without any inside line - :bar_chart: Plotly / Plotly Python - Plotly Community Forum)?

import plotly.graph_objects as go
import numpy as np
from numpy import pi, sin, cos

x= [0,1,0]
y= [0,0,1]
z= [0,0,0]


linemode={'width': 5, 'color': 'black'}
fig = go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=2,surfacecolor='purple', marker_size=3,line=linemode))

fig.add_scatter3d(x=[0,1, 0],  y=[0, 0, 1],  z=[1,1,1], 
                              surfaceaxis=2, surfacecolor='purple',
                             marker_size=3, line=linemode)
fig.show()

image

@Bijan

Please, try to understand how different lines of code work. In my answer I said to add to your initial code the above mentioned line.
Your last plot its OK, for the two parallel planes, but you have to add the code for the remaining surfaces.

import plotly.graph_objects as go
import numpy as np
from numpy import pi, sin, cos

x= [0,1,0,0,0,1,0,0]
y= [0,0,1,0,0,0,1,0]
z= [0,0,0,0,1,1,1,1]


linemode={'width': 5, 'color': 'black'}
fig = go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=1,surfacecolor='purple', marker_size=3,line=linemode))
fig.add_scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=2,surfacecolor='purple', marker_size=3,line=linemode)
fig.add_scatter3d(x=x, y=y, z=z, mode="lines+markers",surfaceaxis=0,surfacecolor='purple', marker_size=3,line=linemode)
fig.add_scatter3d(x=[0,1, 0],  y=[0, 0, 1],  z=[1,1,1], 
                              surfaceaxis=2, surfacecolor='purple',
                             marker_size=3, line=linemode)
fig.show()

From now one, remember that you must provide for each surface only the x, y, z coordinates of the points belonging to that surface, exactly as I did in the last scatter3d. If you give more points there is a high probbaility to “confuse” plotly in selecting the right ones.

1 Like