显示独特的颜色以获得独特的价值 [英] Show unique color for unique value

查看:69
本文介绍了显示独特的颜色以获得独特的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过读取图像获得的2d numpy数组.数组的唯一值是 0、1 和 2.我想绘制分别显示值 0、1 和 2 的唯一颜色红色、绿色和蓝色的图像.

I have a 2d numpy array obtained by reading from an image. The unique values of the array are 0, 1, and 2. I want to plot the image showing unique colors red, green, and blue for the values 0,1, and 2 respectively.

plt.imshow(data, cmap=colors.ListedColormap(['red'])

你会怎么做?

推荐答案

from matplotlib.colors import from_levels_and_colors
cmap, norm = from_levels_and_colors([0,1,2,3],['red','green','blue'])
plt.imshow(data, cmap=cmap, norm=norm)

这篇关于显示独特的颜色以获得独特的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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