필터 지우기
필터 지우기

How to discretize the color in contour bar at smallest possible range?

조회 수: 24 (최근 30일)
Sunny Kumar
Sunny Kumar 2023년 2월 3일
댓글: DGM 2023년 2월 3일
I am trying to put the different color at smallest ranges like 0.0005-0.005, 0.005-0.009, 0.01-0.05, 0.05-0.1, 0.1-0.25, 0.25-0.5, 0.5-0.75, 0.75-1, 1-1.5, 1.5-2, 2-2.5, 2.5-3. Now, I get the plot in which fill the same color in range between 0-0.5 but I want to decrease the range 0-0.0001 in which only one color fill then it will change for other range like 0.0001-0.005. how to do it?
I write the code in given below. Thank you
contourf(X,Y,Z)
cmap = jet(200);
set(gca, 'Colormap',cmap)
cb = colorbar();
caxis([0,3])
set(cb, 'Ticks', 0:0.25:3)
ylabel(cb, 'Att rate')

답변 (2개)

KSSV
KSSV 2023년 2월 3일
% Make data for demo
[X,Y,Z] = peaks ;
vals = [0.000 0.005;
0.005 0.009 ;
0.01 0.05 ;
0.05 0.1;
0.1 0.25;
0.25 0.5 ;
0.5 0.75 ;
0.75 1 ;
1 1.5 ;
1.5 2 ;
2 2.5 ;
2.5 3] ;
% As Z is in different range get it into range [0 3] here
Z = (3-0)*(Z-min(Z(:)))./(max(Z(:))-min(Z(:)))+0 ;
Z0 = Z ;
% Change the values in Z according to color
for i = 1:size(vals,1)
idx = Z0 >= vals(i,1) & Z0 < vals(i,2) ;
Z(idx) = vals(i,2) ;
end
contourf(X,Y,Z0)
cmap = jet(size(vals,1));
set(gca, 'Colormap',cmap)
cb = colorbar();
set(cb, 'Ticks', 0:0.25:3)
ylabel(cb, 'Att rate')
  댓글 수: 1
DGM
DGM 2023년 2월 3일
Inspection shows that the plot colors don't visually correspond to the intervals shown on the colorbar, as there are 7 levels in the plot, but 12 intervals on the colorbar.

댓글을 달려면 로그인하십시오.


DGM
DGM 2023년 2월 3일
Since you didn't specify the levels or even the number of levels in the call to contourf(), there is no reason to suspect that they occur at particular points on some quasi-log scale. Otherwise, the colorbar would be nothing but misleading. You'll have to specify your levels in the call to contourf(), specify an appropriate-length colormap, and set the colorbar ticks accordingly.
See this example:

카테고리

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