Plotly-Python中添加多个Mesh3d至同一图形时图形缺失问题
问题:Plotly组合多个Mesh3d后部分图形丢失
我尝试用Plotly在同一图形中添加4个不同的Mesh3d(屋顶、地面、两面墙体)来闭合一个形状。单独绘制每个Mesh都能正常显示,但组合后部分图形信息丢失。
1. 获取绘图坐标数据
import numpy as np import plotly.graph_objects as go def get_data(n=100): # === n:number of samples x = np.linspace(0, 30, n) y = np.linspace(-1, 1, n) X, Y = np.meshgrid(x, y) Y = Y * np.sqrt(5 / X.max() * X + 4) Z = 2 * 1.2 ** (-X) + 1 # === limit z data to maximum of 2 Z[ Z > 2] =2 # === Close the shape from x=0 and x=max for i in range(len(Z)): Z[i][0] = 0 Z[i][-1] = 0 x = X.flatten() y = Y.flatten() z = Z.flatten() # === return 1d and 2d data, for further figure plotting return np.array([x,y,z,X,Y,Z], dtype=object)
2. 绘制数据
def fig_plot(d, n=100): # === plot the data set # === d:data, n:number of samples fig = go.Figure(data=[go.Mesh3d(x=d[0], y=d[1], z=d[2], name="Roof", opacity=0.50)]) # === Add other mesh fig.add_trace(go.Mesh3d(x=[0, 30, 30, 0], y=[-2, -3, 3, 2], z=[0, 0, 0, 0], name="Floor")) fig.add_trace(go.Mesh3d(x=d[3][-1], y=d[4][-1], z=d[5][-1], name="Back Wall", opacity=0.50)) fig.add_trace(go.Mesh3d(x=d[3][0], y=d[4][0], z=d[5][0], name="Front Wall", opacity=0.50)) # === save file fig.write_html("fov_plot.html") return
3. 运行函数
data = get_data(n=100) fig_plot(data)
我尝试过调整Mesh的添加顺序(比如将墙体作为主图形,屋顶作为附加trace),但仍然存在图形缺失问题。
内容的提问来源于stack exchange,提问作者Hady Farrag
相关产品推荐
相关产品推荐

