Matplotlib 保存 imshow 数组 [英] Matplotlib Save imshow array

查看:34
本文介绍了Matplotlib 保存 imshow 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能保存 imshow 函数的数组?这是什么意思?

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

好吧,我有一个具有唯一值的二维数组.我希望看到用颜色表示,所以我自然会使用 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).您的 data 需要缩放到 [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].

这篇关于Matplotlib 保存 imshow 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆