可视化由 1 和 0 组成的 3d numpy 数组

rjp*_*998 1 python arrays 3d numpy

好吧,伙计们,我有这个 1 和 0 的 3d 数组,它应该代表一个 3d 对象。0 表示那里什么也没有。1 表示对象存在于该坐标中。我需要在屏幕上显示 3D 对象。对我来说,拥有一个具有取决于颜色的值的离散 3 维图将是理想的。我尝试查看 glumpy 和 vispy 但文档页面现在似乎已关闭。

Eri*_*ric 5

我向 matplotlib 发出了一个拉取请求,它正是执行此操作,添加了该ax3d.voxels函数。不幸的是,它尚未得到充分审查。

更新:这已进入 matplotlib 2.1

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# your real data here - some 3d boolean array
x, y, z = np.indices((10, 10, 10))
voxels = (x == y) | (y == z)

ax.voxels(voxels)

plt.show()
Run Code Online (Sandbox Code Playgroud)

结果图