python - 如何在plotly 3D中绘制不同高度的多个正方形

标签 python plotly geometry-surface

我正在尝试在 3D 绘图中的不同高度上绘制与 xy 平面平行的区域 1 正方形。我可以对点进行操作,这基本上是分散的,代码如下所示:

A=np.array([[213,254,245,217,198],[245,201,211,249,200],[211,189,32,212,227],[250,234,217,243,188],[222,243,212,209,199]])
points={}
for i in range(5):
    for j in range(5):
        points[i*5+j]={'x':i,'y':j,'z':A[i][j]}


data=pd.DataFrame(points)
data1=pd.DataFrame.transpose(data)
fig = px.scatter_3d(data1,x='x', y='y', z='z')
fig.show()

enter image description here

我还可以在不同高度绘制平行于 xy 平面的线段:

enter image description here

这些是矩阵A的0-骨架和1-骨架。现在我需要绘制2个骨架,它是不同高度的多个正方形。我尝试使用 go.Surface,但这些表面覆盖了整个空间并且它们彼此相交。我需要的是离散的区域 1 补丁,其投影是矩阵 A 或灰度图,如下所示: enter image description here

最佳答案

您可以添加许多小正方形表面,如下所示:

import plotly.graph_objects as go

def add_hovering_square(fig, x0, y0, size, height):
    fig.add_trace(go.Surface(
        z=[[height,height],[height,height]],
        x=[x0,x0+size], y=[y0,y0+size],
        coloraxis='coloraxis1'
    ))

fig = go.Figure()

add_hovering_square(fig, 1, 1, 1, 1)
add_hovering_square(fig, 1, 2, 1, 2)
add_hovering_square(fig, 2, 1, 1, 3)
add_hovering_square(fig, 2, 2, 1, 4)

fig.show()

enter image description here

关于python - 如何在plotly 3D中绘制不同高度的多个正方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58002152/

相关文章:

matlab - 为 MATLAB 曲面图中的特定点着色

python - Plotly:如何为 create_displot 图添加均值和标准差?

删除显示在条形图条形图上的文本

python - 如何在没有 setter 的属性上使用 += 运算符?

python - 你如何在 numpy 数组中查找和保存重复的行?

r - mesh3d如何为三角形的面着色 R Plotly

unity-game-engine - 顶点相对于法线的位置

directx - 从 Direct3D 纹理和表面进行回读

python - Plotly:如何在多行上绘制分组结果?

python - 运行python程序时出现"SyntaxError: Non-ASCII character '\xfe ' in file"错误