Color from contourf and colorbar doesn't match

조회 수: 4 (최근 30일)
Mike
Mike 2011년 1월 22일
I am using ‘contourf ’to create a filled 2-D contour plot, and using the ‘caxis‘ to control the max and min colorvalue. And then I used the ‘colorbar’ to create a colorbar. But the colorbar and the color on the figure doesn't match. If I change
cp=jet(4);%colormap
colormap(cp);
to
cp=jet(5);%colormap
colormap(cp);
The colorbar will be totally messed up.
Here is the code. Please help.
**************
clc;
clear
cf2=[0.8163 0.8425 0.8595 0.8581 0.7743 0.6571 0.8534 0.8522;0.7918 0.8053 0.8033 0.7986 0.7934 0.7889 0.7724 0.7874;0.7771 0.7909 0.7969 0.8502 0.8137 0.7955 0.6184 0.6209];
figure;
nn=0.6;
[c,h]=contour(cf2,[nn:0.1:1]);
contourf(cf2,[nn:0.1:1]);
clabel(c);
caxis([nn,1]);
cp=jet(4);
colormap(cp);
h1=colorbar;
set(h1,'Ylim',[nn,1]);
set(h1,'YTick',nn:0.1:1);
set(h1,'YTickLabel',nn:0.1:1);

답변 (1개)

Sam G.
Sam G. 2011년 1월 24일
Well, this may not be a very satisfying solution but if you change
nn=0.6
to
nn=0.60000001
the colorbar will then match the contour plot. Changing
caxis([nn,1])
to
caxis([nn,0.9999999])
also seems to work.

카테고리

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