如何使用 3D Mesh Plotly 在 1 个图中绘制多于 1 个图形?

How to plot more than 1 graph in 1 figure with 3D Mesh Plotly?

我的绘图有问题。 我想在一张图中绘制多个网格,每个网格都用标签标记。

数据是这样的:

我只能绘制 1 个网格。请帮忙

这是我的代码(只有一个网格):

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()

您的问题是理解您要在 3D 图形上绘制两个网格的代码。关键是为每个标签提取并添加一个图表。

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()