You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Matplotlib绘制.npy三维数组图像为何近乎全白?

问题:Matplotlib绘制.npy三维数组图像近乎全白

我尝试用Matplotlib绘制一个值范围为-90至315的三维数组.npy文件,但生成的图像几乎全白,只有零星彩色斑点。

使用的代码如下:

file = "file.npy"

img_array = np.load(file)

img = (img_array - img_array.min()) / (img_array.max() - img_array.min()) * 255

plt.imshow(img, vmin=0, vmax=255)
plt.show()

绘图结果:
近乎全白的图像,仅少量彩色斑点

求问该问题的原因及正确绘图方法,感谢解答!


已解决:转换数组数据类型为int8

问题根源在于数组的数据类型为float32,将归一化后的数组转换为int8类型后,图像显示恢复正常。

修改后的代码示例:

import numpy as np
import matplotlib.pyplot as plt

file = "file.npy"

img_array = np.load(file)

# 归一化后转换为int8类型
img = ((img_array - img_array.min()) / (img_array.max() - img_array.min()) * 255).astype(np.int8)

plt.imshow(img, vmin=0, vmax=255)
plt.show()

内容的提问来源于stack exchange,提问作者liz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 06:22:06