フィルターのクリア

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)?
  1 件のコメント
Adam Danz
Adam Danz 2023 年 7 月 19 日
編集済み: Adam Danz 2023 年 7 月 19 日
FYI, I've removed the attachment. The function can be found on the File Exchange:
cbarf (author: @M MA).

サインインしてコメントする。

採用された回答

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 Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by