create a custom colormap

9 ビュー (過去 30 日間)
kim chan
kim chan 2020 年 5 月 22 日
回答済み: Ameer Hamza 2020 年 5 月 22 日
hi all,
I would like to customize a colormap with specified color for each value range (from -4 to 2, a total of 7 intervals, and assign a color for each interval):
% a three-column matrix of RGB triplets for each interval:
map = [0.4940 0.1840 0.5560
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
1 1 0
0.4660 0.6740 0.1880
0 0.75 0.75
0 0.5 0];
% here is part of my codes:
image = imshow(x);
......
caxis([-4 2])
colorbar('Ticks',[-4 -3 -2 -1 0 1 2],...
'TickLabels',{'-4','-3','-2','-1','0','1','2'})
colormap(map)
The location of the label tick is not on the boundary between two color and I don't know how to fix it. Does anyone have an idea on this question?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 22 日
Because there are 6 unit-sized intervals between -4 and 2, you should use 6 colors in the map. Try this
map = [0.4940 0.1840 0.5560
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
1 1 0
0.4660 0.6740 0.1880
0 0.75 0.75];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by