color bar related issue

1 view (last 30 days)
vijay P
vijay P on 18 Oct 2019
Edited: Adam Danz on 15 Nov 2019
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

Answers (1)

Adam Danz
Adam Danz on 18 Oct 2019
Edited: Adam Danz on 18 Oct 2019
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
vijay P on 18 Oct 2019
Thank you so much Adam Danz for your swift reply.
I am interested in Example 1.
Thank you
Vijay
Adam Danz
Adam Danz on 18 Oct 2019
Edited: Adam Danz on 15 Nov 2019
Glad I could help! Let us know if you run into any problems with example 1.

Sign in to comment.

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!