color bar related issue
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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);
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!