Customize a colormap

4 ビュー (過去 30 日間)
Hugo Policarpo
Hugo Policarpo 2011 年 8 月 26 日
  1. Hello,I would like to customize a colormap to be able to have four regions. Example, for x>1 (red); for 0.1<x<1 (orange); for 0.01<x<0.1 (yellow); for x<0.01 (green).It can be linear interpolated between the intervals or just plain simple.Any help is appreciated.Thanks,Hugo Policarpo

採用された回答

Paulo Silva
Paulo Silva 2011 年 8 月 26 日
maybe this
c=zeros(64,3);
c(1:16,1)=1; %red
c(17:32,1)=1; %orange
c(17:32,2)=0.5; %orange
c(33:49,1)=1; %yellow
c(33:49,2)=1; %yellow
c(50:end,2)=1; %green
load flujet
imagesc(X/max(X(:)))
colormap(c)
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 8 月 26 日
Note that the above colormap is upside-down and does not match the proportions requested, such as 1/100 of the map being green, and (1/10 - 1/100) of the map being yellow.
Hugo Policarpo
Hugo Policarpo 2011 年 8 月 26 日
First of all thanks!
the upside-down part is quite straight foward. What I've been battling with is to associate the data intervals with the colors.Just like I stated before,Example, for x>1 (red); for 0.1<x<1 (orange); for 0.01<x<0.1 (yellow); for x<0.01 (green).

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 8 月 26 日
colormaps cannot be used like that, not unless you are able to define a strict lower and upper bound on x. pseudocolor works by mapping the lowest data value to the lowest color, and the highest data value to the highest color, with everything in-between linearly interpolated according to (x-min(x)) .* (number_of_map_entries ./(max(x)-min(x)))
If you want particular fixed data values to map to particular colors, then you will need to either use RGB instead of pseudocolor (choosing the RGB color yourself), or else you will need to create a color map that has as many entries as different states you want and then map your data to the state number before submitting it to be plotted.
  2 件のコメント
Daniel Shub
Daniel Shub 2011 年 8 月 26 日
You do not need to bound x. You can just bound CLim and replace x with CLim in your equation.
Hugo Policarpo
Hugo Policarpo 2011 年 8 月 26 日
I'll try your sugguestion Walter.
Thanks

サインインしてコメントする。


Daniel Shub
Daniel Shub 2011 年 8 月 26 日
mesh(peaks)
colorbar
set(gca, 'CLim', [0, 1.01])
set(gcf, 'ColorMap', [0, 1, 0; repmat([1, 1, 0], 9, 1); repmat([1, 0.5, 0], 90, 1); [1, 0, 0]])
  2 件のコメント
Hugo Policarpo
Hugo Policarpo 2011 年 8 月 26 日
yes, you can get close. But I have a 2400x100 data points and don't really know how many are in each color region, and these vary with each analysis.
Daniel Shub
Daniel Shub 2011 年 8 月 26 日
See my edit. It now gives the correct answer without any "rounding" issues.

サインインしてコメントする。

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by