color bar related issue

1 次查看(过去 30 天)
vijay P
vijay P 2019-10-18
编辑: Adam Danz 2019-11-15
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

回答(1 个)

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by