Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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)?

Akzeptierte Antwort

Adam Danz
Adam Danz am 19 Jul. 2023
Bearbeitet: Adam Danz am 19 Jul. 2023
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 Kommentare
Ankitkumar Patel
Ankitkumar Patel am 19 Jul. 2023
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 am 19 Jul. 2023
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by