python - 您将如何在 Python 中绘制此 3D 可视化图?

标签 python matplotlib plotly

我想拍摄一张图像,并将图像的维度表示为空间坐标,将像素值表示为由高度表示的第 3 维。这是一个 example我想做的事。

你会如何使用 matplotlib 或 plotly 做到这一点?

最佳答案

假设图像是 HWC 格式,是灰度(即 C=1)并且是一个 numpy 数组,类似于:

import matplotlib.pyplot as plt
import numpy as np

img = np.random.uniform(size=(10,10,1))

X = np.arange(0, img.shape[1])
Y = np.arange(0, img.shape[0])
X, Y = np.meshgrid(X, Y)
Z = img.squeeze()

# Plot the surface.
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z)

灵感来自:this . 希望这对您有所帮助!

关于python - 您将如何在 Python 中绘制此 3D 可视化图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58547483/

相关文章:

python - 如何忽略复数的 Python 警告

python - 打乱 pandas 数据框中的行,将重复项保留在一起

python - 有没有办法在谷歌应用引擎中查看内存缓存数据?

python - matplotlib:按没有规范化的字典着色

python - 使用 plotly 在一个图中绘制多条 3d 线

python - pygame - 粒子效果

python - 使用 matplotlib 的银河和赤道投影网格

python - 如何更新第二个绘图轴图 Scatter3D 子图

python - 在离线模式下删除 "Save and edit plot in cloud"- 按钮

python - 自动编码器分类绘制 Roc 曲线