MATLAB Answers

vijay P
0

color bar related issue

Asked by vijay P
on 18 Oct 2019 at 10:42
Latest activity Edited by Adam Danz
on 21 Oct 2019 at 21:01
Dear all,
I have a color bar limits ranging from -10 to 10 with jet colormap but i want to put gray scale -5 to 5 on the same color bar. It is like combination of jet (-10 to -5 & 5 to 10) and gray (-5 to 5) How can i do?
Thanks
vijay

  0 Comments

Sign in to comment.

1 Answer

Adam Danz
Answer by Adam Danz
on 18 Oct 2019 at 11:42
Edited by Adam Danz
on 18 Oct 2019 at 11:55

By 'gray', I assum you mean the gray colormap.
Here are a few interpretations. The first example creates the entire range of the jet colormap, separates it in the middle, and places the gray colormap in between. The second example creates the entire range of the jet colormap but replaces the middle half with the gray colormap. The third example shows how to use a solid gray color instead of gray scale.
% Choose number of colors in the entire colormap
nColors = 120; % any value divisible by 4!
% Create both colormaps, then combine
colormap1 = jet(nColors/2);
colormap2 = gray(nColors/2);
colormapCombo = [colormap1(1:nColors/4,:); colormap2; colormap1(nColors/4+1:end,:)];
% Create the figure
figure()
axes()
% Set the colormap
colormap(colormapCombo)
cbh = colorbar();
caxis([-10,10])
cbh.YTick = -10:5:10;
Or perhaps you mean,
nColors = 120; % any value divisible by 4
colormapCombo = jet(nColors);
colormapCombo(nColors*1/4+1:nColors*3/4,:) = gray(nColors/2);
Or maybe you want to use a solid gray color.
% First method above,
colormap1 = jet(nColors/2);
colormap2 = repmat([.5 .5 .5], nColors/2 ,1);
colormapCombo = [colormap1(1:nColors/4,:); colormap2; colormap1(nColors/4+1:end,:)];
% Second method above
colormapCombo1 = jet(nColors);
colormapCombo1(nColors*1/4+1:nColors*3/4,:) = repmat([.5 .5 .5], nColors/2 ,1);
191018 075333-Figure 2.png

  2 Comments

vijay P
on 18 Oct 2019 at 12:46
Thank you so much Adam Danz for your swift reply.
I am interested in Example 1.
Thank you
Vijay
Adam Danz
on 18 Oct 2019 at 12:54
Glad I could help! Let us know if you run into any problems with example 1.
Please consider accepting the answer if this was helpful to you (blue accept button).

Sign in to comment.