필터 지우기
필터 지우기

How can I replace white color with some other color while keep using cbarf for values less than cutoff mark?

조회 수: 1 (최근 30일)
data = rescale(peaks,0,600);
newTickVals = [ 100 300 350 450];
limits=[newTickVals(1) newTickVals(end)];
x=1:1:49;z=ones(size(x));
f1=figure('Position', [0 400 800 500]);
axes( ...
'Parent' ,f1, ...
'Units' , 'normalized' );
contourf(data,newTickVals, "ShowText" , "on" )
C=colormap( 'parula' );
colormap(flipud(C))
h1=cbarf(data,newTickVals);
How can I replace white color (<100 values) with some other color (let say red) while keep using cbarf (attached)?

채택된 답변

Adam Danz
Adam Danz 2023년 7월 19일
편집: Adam Danz 2023년 7월 19일
Interesting function cbarf (author: @M MA).
That white section is just your axes background. One hacky solution is to set the axes color which works well with filled contours. An alternative would be to create a patch that covers the white area. This would be considerably more work but not impossible. Additionally, you'll need to update the color of the lower triangle in the pseudo-colorbar.
Recreate the figure
data = rescale(peaks,0,600);
newTickVals = [ 100 300 350 450];
limits=[newTickVals(1) newTickVals(end)];
x=1:1:49;z=ones(size(x));
f1=figure('Position', [0 400 800 500]);
axes( ...
'Parent' ,f1, ...
'Units' , 'normalized' );
contourf(data,newTickVals, "ShowText" , "on" )
C=colormap( 'parula' );
colormap(flipud(C))
h1=cbarf(data,newTickVals);
Change color
Choose a new color
newColor = 'r'; % or [1 0 0]
Make the change
set(gca,'color', newColor)
cbax = findall(f1,'Tag','cbarf_vertical_linear');
cbax.Children(1).FaceColor = newColor;
  댓글 수: 2
Ankitkumar Patel
Ankitkumar Patel 2023년 7월 19일
I think this fails whenever we have Nan values in data beacuse than Nan value patch will also be in red.
Adam Danz
Adam Danz 2023년 7월 19일
True, if there are nans, the holes in the filled contour will appear as red in this hacky solution.
You could get the contour coordinates to create a patch object that is plotted on top of the controur regions at z<100.
There are a number of functions on the file exchange that help to get the contour coordinates. Example: getContourLineCoord​inates

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by