1

Below is code I use to plot a 3D mesh. Is there a way to plot multiple meshes on 1 graph? For this example, I would want fig1 and fig2 to be shown on the same graph/figure.

import plotly.graph_objects as go
import numpy as np

# Download data set from plotly repo
pts = np.loadtxt(np.DataSource().open('https://raw.githubusercontent.com/plotly/datasets/master/mesh_dataset.txt'))
x, y, z = pts.T

fig1 = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z, color='lightpink', opacity=0.50)])
fig1.show()

fig2 = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z-2, color='cyan', opacity=0.50)])
fig2.show()

1 Answers1

3

You can use add_trace to add to an existing figure.

import plotly.graph_objects as go
import numpy as np

# Download data set from plotly repo
pts = np.loadtxt(np.DataSource().open('https://raw.githubusercontent.com/plotly/datasets/master/mesh_dataset.txt'))
x, y, z = pts.T

fig1 = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z, color='lightpink', opacity=0.50)])
fig1.add_trace(go.Mesh3d(x=x, y=y, z=z-2, color='cyan', opacity=0.50))
fig1.show()

enter image description here

Alex
  • 1,042
  • 1
  • 8
  • 17