I have a problem with my plotting. I want to plot multiple meshes in one graph, and each mesh is marked by label.
This is what the data looks like:
I only could plot 1 mesh. Please help.
this is my code (just one mesh) :
import numpy as np
import pandas as pd
import plotly.graph_objects as go
geob_data = pd.read_csv("Geobody.csv")
x = list(geob_data["X"])
y = list(geob_data["Y"])
z = list(geob_data["Z"])
label = list(geob_data["LABEL"])
fig = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z, color='green',
opacity=1, alphahull=0)])
fig.show()
Your question was code with the understanding that you want to draw two meshes on a 3D graph. The key is to extract and add a graph for each label.
import pandas as pd
import io
data = '''
X Y Z LABEL
500 500 -200 1
500 500 -180 1
505 505 -190 1
495 495 -190 1
495 505 -190 1
505 495 -190 1
400 400 -150 2
400 400 -130 2
405 405 -140 2
395 395 -140 2
395 405 -140 2
405 395 -140 2
'''
geob_data = pd.read_csv(io.StringIO(data), delim_whitespace=True)
import plotly.graph_objects as go
#geob_data = pd.read_csv("Geobody.csv")
x = list(geob_data["X"])
y = list(geob_data["Y"])
z = list(geob_data["Z"])
label = list(geob_data["LABEL"])
fig = go.Figure()
for lbl in geob_data['LABEL'].unique():
df = geob_data.query('LABEL == @lbl')
colors = 'green' if lbl == 1 else 'red'
fig.add_trace(go.Mesh3d(x=df['X'].tolist(),
y=df['Y'].tolist(),
z=df['Z'].tolist(),
color=colors,
opacity=1,
alphahull=0
))
fig.update_layout(
autosize=False,
height=600,
width=600,
)
fig.show()