
create a custom colormap
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
kim chan
le 22 Mai 2020
Réponse apportée : Ameer Hamza
le 22 Mai 2020
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?

0 commentaires
Réponse acceptée
Ameer Hamza
le 22 Mai 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Color and Styling dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!