Problem with adjusting custom colormap and colorbar

5 views (last 30 days)
Hello everyone
How to adjust a color bar in this way?
lower than 0.05 = white
0.05 ~ 0.1 = red
0.1 ~ 0.2 = yellow
0.2 ~ 0.3 = green
0.4 ~0.5 = blue
greater than 0.5 = black
Here is my try:
mycolormap = [1 1 1; 1 0 0; 1 1 0; 0 1 0; 0 0 1;0 0 0 ];
colormap (mycolormap)
caxis([0.05, 0.5])
c=colorbar('XTickLabel',{'0.05','0.1','0.2','0.3','0.4','0.5'});
But unfortunately here is my color bar:
which the colors not correctly showing and also color bar tick labels are not consonant.
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 3 Aug 2020
The colormap process is uniform mapping. All bars are the same size. However you can assign the same color to multiple bars.
white
red
yellow
yellow
green
green
blue
blue
black
also note that for mapping purposes, you cannot say "less than" and assign a color to that condition. You need to assign a slot of equal size to the other slots. This can require you to expand your caxis

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!