绘制具有正确纵横比的 3D 图
Plotly 3D plot with right aspect ratio
相关的 post 在这里:
为了进一步改进,我想知道如何根据容器大小绘制容器框架,以便图形可以更清楚地显示容器未满时还剩下多少备用space?如下图所示:
更新:绘制外部容器框架
def parallelipipedic_frame(xm, xM, ym, yM, zm, zM):
# defines the coords of each segment followed by None, if the line is
# discontinuous
x = [xm, xM, xM, xm, xm, None, xm, xM, xM, xm, xm, None, xm, xm, None, xM, xM,
None, xM, xM, None, xm, xm]
y = [ym, ym, yM, yM, ym, None, ym, ym, yM, yM, ym, None, ym, ym, None, ym, ym,
None, yM, yM, None, yM, yM]
z = [zm, zm, zm, zm, zm, None, zM, zM, zM, zM, zM, None, zm, zM, None, zm, zM,
None, zm, zM, None, zm, zM]
return x, y, z
x, y, z = parallelipipedic_frame(0, 1202.4, 0, 235, 0, 269.7)
# fig = go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines", line_width=4))
fig.add_trace(
go.Scatter3d(
x=x,
y=y,
z=z,
mode="lines",
line_color="blue",
line_width=2,
hoverinfo="skip",
)
)
ar = 4
xr = max(d["x"].max()) - min(d["x"].min())
fig.update_layout(
title={"text": pbin, "y": 0.9, "x": 0.5, "xanchor": "center", "yanchor": "top"},
margin={"l": 0, "r": 0, "t": 0, "b": 0},
# autosize=False,
scene=dict(
camera=dict(eye=dict(x=2, y=2, z=2)),
aspectratio={
**{"x": ar},
**{
c: ((max(d[c].max()) - min(d[c].min())) / xr) * ar
for c in list("yz")
},
},
aspectmode="manual",
),
)
要获得逼真的 3d 绘图,您应该在布局中进行设置,scene_aspectmode='data'
。
要绘制容器框架,从用于绘制体素的数据中检索,x.min(), x.max(), y.min(), y.max(), z.min(), z.max()
,如果 x、y、z 是数组或 min(x) 等,如果它们是列表。然后在你的 plotly 图中添加一个 scatter3d 图,mode="lines"
来绘制容器框架的线条。我检查了它是否有附加到我自己的体素图的部分框架,它有效:
框架由线段组成,线段在两点之间绘制。因此,我不能仅根据您的长度、宽度和高度给出绘制框架的代码。
我需要平行六面体顶点的坐标,即 x.min()、x.max()、y.min()、y.max() 等(见上文),表示为 xm , xM, ym, yM, zm, zM:
import plotly.graph_objects as go
def parallelipipedic_frame(xm, xM, ym, yM, zm, zM):
#defines the coords of each segment followed by None, if the line is
discontinuous
x = [xm, xM, xM, xm, xm, None, xm, xM, xM, xm, xm, None, xm, xm, None, xM, xM,
None, xM, xM, None, xm, xm]
y = [ym, ym, yM, yM, ym, None, ym, ym, yM, yM, ym, None, ym, ym, None, ym, ym,
None, yM, yM,None, yM, yM]
z= [zm, zm, zm, zm, zm, None, zM, zM, zM, zM, zM, None, zm, zM, None, zm, zM,
None, zm, zM, None, zm, zM]
return x, y, z
x, y, z= parallelipipedic_frame(2.3, 4.5, 0,5, 0, 2)
fig=go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines", line_width=4))
fig.update_layout(width=600, height=450, font_size=11, scene_aspectmode="data",
scene_camera_eye=dict (x=1.45, y=1.45, z=1), template="none")
fig.show()
相关的 post 在这里:
为了进一步改进,我想知道如何根据容器大小绘制容器框架,以便图形可以更清楚地显示容器未满时还剩下多少备用space?如下图所示:
更新:绘制外部容器框架
def parallelipipedic_frame(xm, xM, ym, yM, zm, zM):
# defines the coords of each segment followed by None, if the line is
# discontinuous
x = [xm, xM, xM, xm, xm, None, xm, xM, xM, xm, xm, None, xm, xm, None, xM, xM,
None, xM, xM, None, xm, xm]
y = [ym, ym, yM, yM, ym, None, ym, ym, yM, yM, ym, None, ym, ym, None, ym, ym,
None, yM, yM, None, yM, yM]
z = [zm, zm, zm, zm, zm, None, zM, zM, zM, zM, zM, None, zm, zM, None, zm, zM,
None, zm, zM, None, zm, zM]
return x, y, z
x, y, z = parallelipipedic_frame(0, 1202.4, 0, 235, 0, 269.7)
# fig = go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines", line_width=4))
fig.add_trace(
go.Scatter3d(
x=x,
y=y,
z=z,
mode="lines",
line_color="blue",
line_width=2,
hoverinfo="skip",
)
)
ar = 4
xr = max(d["x"].max()) - min(d["x"].min())
fig.update_layout(
title={"text": pbin, "y": 0.9, "x": 0.5, "xanchor": "center", "yanchor": "top"},
margin={"l": 0, "r": 0, "t": 0, "b": 0},
# autosize=False,
scene=dict(
camera=dict(eye=dict(x=2, y=2, z=2)),
aspectratio={
**{"x": ar},
**{
c: ((max(d[c].max()) - min(d[c].min())) / xr) * ar
for c in list("yz")
},
},
aspectmode="manual",
),
)
要获得逼真的 3d 绘图,您应该在布局中进行设置,scene_aspectmode='data'
。
要绘制容器框架,从用于绘制体素的数据中检索,x.min(), x.max(), y.min(), y.max(), z.min(), z.max()
,如果 x、y、z 是数组或 min(x) 等,如果它们是列表。然后在你的 plotly 图中添加一个 scatter3d 图,mode="lines"
来绘制容器框架的线条。我检查了它是否有附加到我自己的体素图的部分框架,它有效:
框架由线段组成,线段在两点之间绘制。因此,我不能仅根据您的长度、宽度和高度给出绘制框架的代码。 我需要平行六面体顶点的坐标,即 x.min()、x.max()、y.min()、y.max() 等(见上文),表示为 xm , xM, ym, yM, zm, zM:
import plotly.graph_objects as go
def parallelipipedic_frame(xm, xM, ym, yM, zm, zM):
#defines the coords of each segment followed by None, if the line is
discontinuous
x = [xm, xM, xM, xm, xm, None, xm, xM, xM, xm, xm, None, xm, xm, None, xM, xM,
None, xM, xM, None, xm, xm]
y = [ym, ym, yM, yM, ym, None, ym, ym, yM, yM, ym, None, ym, ym, None, ym, ym,
None, yM, yM,None, yM, yM]
z= [zm, zm, zm, zm, zm, None, zM, zM, zM, zM, zM, None, zm, zM, None, zm, zM,
None, zm, zM, None, zm, zM]
return x, y, z
x, y, z= parallelipipedic_frame(2.3, 4.5, 0,5, 0, 2)
fig=go.Figure(go.Scatter3d(x=x, y=y, z=z, mode="lines", line_width=4))
fig.update_layout(width=600, height=450, font_size=11, scene_aspectmode="data",
scene_camera_eye=dict (x=1.45, y=1.45, z=1), template="none")
fig.show()