Is it possible to create this colormap and corresponding colorbar in Matlab?
Show older comments
Hello,
I want to use something like this colorbar on my figure:
Which you can see every 25 by 25 the color has changed. Now I want:
-------------------------------------------------
0-25 = #fff496
25-50 = #fcd70d
50-75= #adff2f
75-100 = #45ff2f
100-125 = #9cb63b
125-150 = #339445
150-175 = #1aa05b
175-200 = #17baa7
200-225 =#159fd0
225-250 = #2f52a4
250 - 275 = #2f449d
275-300 = #4f499f
300-325 = #7550a0
325-350 = #50376d
more than 350 = #2b1d3a
---------------------------------------------
I don't know how to set something like this. Here is my code:
S = shaperead ('country_Boundary.shp');
lon = S.X;
lat = S.Y;
plot(lon, lat, '-k')
hold on
ax = gca;
xL = ax.XLim;
yL = ax.YLim;
rect_x = [-0.25 -0.25 0.25 0.25];
rect_y = [0.25 -0.25 -0.25 0.25];
x = points{:,1};
y = points{:,2};
z = points{:,3};
colorbar
% define start and end colors Using the hex -> rgb converter from this answer: https://www.mathworks.com/matlabcentral/answers/458086-how-to-specify-line-color-using-a-hexadecimal-color-code
start_color = sscanf('00ffff','%2x%2x%2x',[1 3])/255;
end_color = sscanf('0000ff','%2x%2x%2x',[1 3])/255;
num_colors = 100;
% create a map linearly interpolating between them
% i.e. three columns interpolating from Red1 to Red2, etc.
clrs =[linspace(start_color(1),end_color(1),num_colors)' linspace(start_color(2),end_color(2),num_colors)' linspace(start_color(3),end_color(3),num_colors)'];
colormap(clrs)
zlim = [min(z) max(z)]+[-0.1 +0.1];
clr_val = @(z) clrs(ceil(interp1(zlim, [0 1], z)*num_colors), :);
for i=1:numel(x)
p(i) = patch(rect_x + x(i), rect_y + y(i), ...
clr_val(z(i)), ...
'EdgeColor', 'none');
end
ax.XLim = xL;
ax.YLim = yL;
caxis([min(z) max(z)])
I attached my data too. Thank you all.
Accepted Answer
More Answers (0)
Categories
Find more on Color and Styling 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!