Matlab自定义颜色图只有3种颜色 [英] Matlab custom colormap with only 3 colors

查看:270
本文介绍了Matlab自定义颜色图只有3种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只想检查是否可以仅制作3种颜色的自定义颜色图? (无需渐变).

just want to check if it is possible to make a custom colormap with only 3 colors? (there is no need for gradient).

示例:数据范围为0-100

  • 所以0-33是一种颜色,
  • 34-67是另一种颜色,
  • 68-100是另一种颜色.
  • so 0-33 is one color,
  • 34-67 is another color,
  • and 68-100 is another color.

推荐答案

只需使用带有三行的色图.每行都根据R,G,B成分定义了一种颜色.

Just use a colormap with three rows. Each row defines a color in terms of R, G, B components.

A = randi(100,16,16); %// example data
imagesc(A) %// display matrix as image
colormap([1 0 0; 0 1 0; 0 0 1]) %// apply colormap
colorbar %// show color bar

这定义了颜色之间均匀间隔的阈值.如果需要更多控制,则需要多于三行,并重复一些颜色.例如,

This defines uniformly spaced thresholds between colors. If you need more control you need to have more than three rows, with some of the colors repeated. For example,

colormap([1 0 0; 1 0 0; 0 1 0; 0 0 1]) %// apply colormap

将为第一种颜色定义50%的阈值,为第二种颜色定义75%的阈值,为第三种颜色定义100%的阈值.

will define a 50% threshold for first color, 75% for second and 100% for third.

这篇关于Matlab自定义颜色图只有3种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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