Custom colour bar, excluding the Blue from RGB.

1 回表示 (過去 30 日間)
Jigsaw
Jigsaw 2020 年 1 月 16 日
コメント済み: Star Strider 2020 年 1 月 17 日
I made a custom colour bar where 100 fell exactly at green and 200 at red. Anything from 0 to 100 along with their colours in insignificant and I'd prefer they do not show up in the colour bar. That being said, I would specifically like to have the colour bar such that it starts at the lowest (green) at 100 and ends at the highest (red) at 200.
untitled.jpg
I used the following code for the image.
figure()
A = [200 200 200 200 200; 200 200 200 200 200; 200 200 100 200 200; 200 200 200 200 200; 200 200 200 200 200];
Percent_matrix = flipud (A);
Percent_Interp = imresize(Percent_matrix,200,'bilinear');
pcolor(Percent_Interp)
shading interp
caxis([0 200])
load CustomColourMap
colormap( CustomColourMap );
colorbar();

採用された回答

Star Strider
Star Strider 2020 年 1 月 16 日
編集済み: Star Strider 2020 年 1 月 16 日
Define ‘CustomColourMap’ as:
CustomColourMap = @(x) [linspace(0,1,x).' linspace(1,0,x).' zeros(x,1)];
then to use it:
CustomColourMap = @(x) [linspace(0,1,x).' linspace(1,0,x).' zeros(x,1)];
figure()
A = [200 200 200 200 200; 200 200 200 200 200; 200 200 100 200 200; 200 200 200 200 200; 200 200 200 200 200];
Percent_matrix = flipud (A);
Percent_Interp = imresize(Percent_matrix,200,'bilinear');
pcolor(Percent_Interp)
shading interp
caxis([100 200])
% load CustomColourMap
colormap( CustomColourMap(64) );
colorbar();
produces:
Custom colour bar, excluding the Blue from RGB - 2020 01 16.png
EDIT —
Corrected typographical error.
  2 件のコメント
Jigsaw
Jigsaw 2020 年 1 月 17 日
The result is perfectly the way i wanted it. Nice of you to display the final image after using the updated code.
Thank you.
Cheers!
Star Strider
Star Strider 2020 年 1 月 17 日
As always, my pleasure!
Thank you! The plot is the intent of your Question and my Answer, so posting it is necessary!

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

その他の回答 (1 件)

Stijn Haenen
Stijn Haenen 2020 年 1 月 16 日
Maybe you can try this:
h=figure();
A = [200 200 200 200 200; 200 200 200 200 200; 200 200 100 200 200; 200 200 200 200 200; 200 200 200 200 200];
Percent_matrix = flipud (A);
Percent_Interp = imresize(Percent_matrix,200,'bilinear');
pcolor(Percent_Interp)
shading interp
caxis([0 200])
colorbar();
h.Children(1).Limits=[100 200];
set(h,'Colormap',[Colormap_data]) % colormap data should be RBG codes: [[0.2422,0.1504,0.66030;0.2444,0.1534,0.6728;0.2464,0.1569,0.6847; ..... ]

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by