Matplotlib保存imshow阵列阵列、Matplotlib、imshow

2023-09-07 12:39:40 作者:此岸花开

我在想,如果它是在所有可能保存imshow功能的阵列?什么意思呢?

I was wondering if it were at all possible to save the array of an imshow function? What do I mean by this?

嗯,我有一个二维数组具有独特的价值。我希望看到psented的颜色重新$ P $,所以我自然会使用imshow函数。据我所知,imshow函数应用一个颜色映射到我的数组,然后显示。我希望能够得到这matplotlib使用,以显示我原来的二维数组中颜色的数组。可以这样做?

Well, I have a 2d array with unique values. I would like to see that represented in colour, so I naturally would use the imshow function. I understand that the imshow function applies a colormap to my array and then displays that. I would like to be able to get the array that matplotlib uses to show my original 2d array in colour. Can this be done?

推荐答案

您可以真正地得到的颜色与马平了 imshow

You can actually just get the color maping with out imshow

data_ = (data - np.min(data))/ (np.max(data) - np.min(data))
my_cmap = matplotlib.cm.get_cmap('gray') # or what ever color map you want
color_array = my_cmap(data_)

color_array 与是形状数组 data.shape +(4),即MxNx4与4存在(R,G,B,A)。需要你的数据来进行缩放以在范围 [0,1]

color_array with be an array of shape data.shape + (4,), that is MxNx4 with the 4 being (r,g,b,a). Your data needs to be scaled to be in the range [0,1].