首页 > 解决方案 > 查看 3D 阵列

问题描述

我有标准化的 3D 数组(介于 0 和 1 之间)数据,我想像这样在 python 中查看它的 3D 格式,颜色与数组中的值匹配。

标签: pythondata-visualization

解决方案


3D 阵列

您可以使用matplotlib.pyplot.scatter3D 投影:

import numpy as np
import matplotlib.pyplot as plt

a = np.random.random(size=(20, 10, 5))

ax = plt.subplot(projection='3d')

grid = np.meshgrid(np.arange(a.shape[2]),
                   np.arange(a.shape[1]),
                   np.arange(a.shape[0]))

x = ax.scatter(*grid, c=a)
plt.colorbar(x)

3D 散点图

二维数组

你可以使用matplotlib.pyplot.imshow

import numpy as np
import matplotlib.pyplot as plt

a = np.random.random(size=(50,100))

plt.imshow(a, vmin=0, vmax=1)
plt.colorbar()

输出:

matplotlib imshow


推荐阅读