【问题标题】:Plotly Volume not rendering random distribution of pointsPlotly Volume 不渲染点的随机分布
【发布时间】:2022-10-09 17:45:09
【问题描述】:

我有来自第三方数据源的 3D 顶点。 plotly Volume 对象期望所有坐标为一维列表。他们网站上的示例使用 mgrid 函数将 3D 空间填充到 flatten 函数中,以获取每个轴的 1D 列表。 https://plotly.com/python/3d-volume-plots/

我不明白为什么我的方法会产生一个空的情节。 coords 是我的 (N, 3) 形状的顶点列表。

请参阅以下代码 sn-p 绘制随机坐标,对它们进行排序,但结果为空渲染。

X = np.random.uniform(0, 1, 30000)
Y = np.random.uniform(0, 1, 30000)
Z = np.random.uniform(0, 1, 30000)
coords = np.dstack((X.flatten(), Y.flatten(), Z.flatten()))[0]

sort_idx = np.lexsort((coords[:, 0], coords[:, 1], coords[:, 2]))
coords = coords[sort_idx]

X=coords[:, 0]
Y=coords[:, 1]
Z=coords[:, 2]
V = np.sin(X) * np.sin(Y) + Z

fig = go.Figure(data=go.Volume(
    x=X,
    y=Y,
    z=Z,
    value=V,
    isomin=np.min(Z),
    isomax=np.max(Z),
    opacity=0.1, # needs to be small to see through all surfaces
    surface_count=20, # needs to be a large number for good volume rendering
    colorscale='Spectral',
    reversescale=True
    ))
fig.show()

更新:似乎 plotly 期望对坐标进行排序。

X, Y, Z = np.mgrid[-50:50:40j, -50:50:40j, -8:8:10j]
coords = np.dstack((X.flatten(), Y.flatten(), Z.flatten()))[0]
np.random.shuffle(coords)

像这样打乱列表并将coords 插入上面的代码会产生一个空的Volumn 渲染。

我现在尝试对我的数据点进行排序,但我仍然得到一个空渲染。如何共享我的数据集? npfile,但我应该在哪里托管它?

sort_idx = np.lexsort((coords[:, 0], coords[:, 1], coords[:, 2]))
coords = coords[sort_idx]

更新 2:使用均匀随机分布生成坐标会导致顶点列表似乎无法通过 plotly 处理甚至排序后。

X = np.random.uniform(0, 1, 30000)
Y = np.random.uniform(0, 1, 30000)
Z = np.random.uniform(0, 1, 30000)
coords = np.dstack((X.flatten(), Y.flatten(), Z.flatten()))[0]

【问题讨论】:

  • 关键的答案是我们为什么要在构建体积时使用网格?!

标签: python plotly


【解决方案1】:

我没有仔细阅读documentation

在 iso-min 和 iso-max 值之间绘制体积轨迹,坐标由四个一维数组给出,这些数组包含均匀或非均匀 3- 的每个顶点的 valuexyz D网格.

输入必须是正交网格的形式;因此Volumn 无法处理随机点云。在这种情况下,非均匀性意味着沿着一个轴(例如,z),“层”不必均匀分布。 Furtunatly 我的数据是几乎以可通过插值固定的网格形状。

【讨论】:

    猜你喜欢
    • 2010-10-07
    • 1970-01-01
    • 2018-11-11
    • 2019-07-16
    • 2019-12-18
    • 1970-01-01
    • 2020-04-04
    • 2011-05-27
    • 1970-01-01
    相关资源
    最近更新 更多