python - 查看 3D 阵列
问题描述
我有标准化的 3D 数组(介于 0 和 1 之间)数据,我想像这样在 python 中查看它的 3D 格式,颜色与数组中的值匹配。
解决方案
3D 阵列
您可以使用matplotlib.pyplot.scatter
3D 投影:
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)
二维数组
你可以使用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()
输出:
推荐阅读
- google-app-engine - 从应用引擎连接到 Kubernetes 引擎
- android - 如何扩展 android.widget 包中的像 DayPickerPagerAdapter 这样的 Android 类?
- python - 将最后 13 行 CSV 复制到新的 CSV
- iis - 在 IIS 中,如何为基本身份验证配置文件夹访问?
- android - Android中两个视图之间的滚动同步
- python-2.7 - Pandas - 如果单元格为空白,则将 pd.timedelta[ns64] 单元格转换为字符串 '--'
- beagleboneblack - 是否可以将 beaglebone(黑色)模拟引脚用作 GPIO?
- c++ - 为什么`::`不像操作符那样被称为“范围解析操作符”?
- javascript - 将 Razor 变量传递给 JavaScript 函数
- javascript - 如何在 laravel 控制器中通过 Cropper Js 接收图像 blob 数据