color bar related issue

조회 수: 2 (최근 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에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by