how to set color range for color in color bar

6 views (last 30 days)
In the following color map, i want to set
<0 values set as variation in brightness in deepskyblue 0-79 interval as variation in light green
79-157 interval as variation (you are right variation in brightness) in yellow
above 157 values as variation in brightness from light red to dark red.
I want to show the value above 157 are dark in red color. This is my upper bound.
Also guide me what kind of interpolation technique matlab use to generate raster surface from point data?
Please help??

Accepted Answer

Walter Roberson
Walter Roberson on 6 Aug 2015
Using the color definitions from http://www.rapidtables.com/web/color/blue-color.htm and the color names that you provided:
total_len = 160; %your description did not give an upper bound
part1_len = 79 - 0 + 1;
part2_len = 156 - 80 + 1;
part3_len = total_len - 157 + 1;
%"variations in blue"... ummm, different brightnesses of blue?
map_part1 = [zeros(part1_len,1), zeros(part1_len,1), linspace(128,255,part1_len).'];
%purple = (128,0,128), yellow = (255,255,0)
map_part2 = [linspace(128, 1, part2_len).', linspace(0, 128, part2_len).', linspace(128, 0, part2_len).'];
%red = (255,0,0), dark red = (139, 0, 0)
map_part3 = [linspace(255, 139, part3_len).', zeros(part3_len,1), zeros(part3_len,1)];
%colormaps need to be in the range 0 to 1 so divide by 255
total_map = [map_part1; map_part2; map_part3] ./ 255;
colormap(total_map);
I rather expect that you are going to be disappointed with your color choices.
  12 Comments
Muhammad Usman Saleem
Muhammad Usman Saleem on 8 Aug 2015
@Kelly i am using that code now
fid = fopen('jan.txt');
C = textscan(fid, '%f %f %f')
fclose(fid);
f = {'lat', 'long', 'temp'}
S = cell2struct(C,f,2);
N = 100;
[Xi, Yi] = meshgrid(linspace(60,80,N),linspace(20,40,N));
Ci = griddata(S.long, S.lat, S.temp, Xi, Yi);
f = figure; set(f, 'Renderer', 'painters')
colormap default
h = geoshow(Yi,Xi,Ci,'DisplayType','surface');
set(h,'ZData', zeros(size(get(h,'XData'))));
p = geoshow('PAK_adm1.shp', 'DisplayType','polygon','FaceColor','none','EdgeColor','w');
xlim([60.5 78.5]);
ylim([22.5 38.5]);
xlabel('LONGITUDE');
ylabel('LATITUDE');
title('JANUARY');
set(gca,'CLim',[0,200])
lim = [-200 200];
cdata = [
-200 0 3 91 0 0 191 255 % -200-0, shades of blue
0 21 176 26 79 150 249 123 % 0-79, shades of green
79 255 255 20 157 206 179 1 % 79-157, shades of yellow
157 229 0 0 200 132 0 0]; % 157+, shades of red
dlmwrite('mycmap.cpt', cdata, ' ');
axes;
[x,y,z] = peaks(100);
z = (z - (min(z(:))))./(max(z(:)) - min(z(:)));
z = z*diff(lim) + lim(1);
pcolor(x,y,z);
shading flat;
cptcmap('mycmap', 'mapping', 'direct', 'ncol', 30*5);
colorbar;
text(64,28,'BALOCHISTAN','Color','w');
text(68,25.5,'SINDH','Color','w');
text(72,32,'PUNJAB','Color','w');
text(61.5,36,'AFGHANISTAN','Color','w');
text(60.5,27,'IRAN','Color','w');
text(63,23,'ARABIAN SEA','Color','w');
text(74.5,28,'INDIA','Color','w');
text(76,37,'CHINA','Color','w');
text(69.899,32.884,'F.A.T.A','Color','w');
text(72.355,34.597,'N.W.F.P','Color','w');
text(74,35.882,'NORTHERN AREAS','Color','w');
text(73.754,33.969,'AZAD KASHMIR','Color','w');
and getting that error now
C =
[323x1 double] [323x1 double] [323x1 double]
f =
'lat' 'long' 'temp'
??? Undefined function or method 'cptcmap' for input arguments of type 'char'.
Please note that in your uploaded map , the color range for -200 to 0 is very long , is this possible , this range can be shrink and remaining range remains unchanged as in your map.Actually i have less data to be in the range of -200 to 0
Regards

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!