Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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)?

Risposta accettata

Adam Danz
Adam Danz il 19 Lug 2023
Modificato: Adam Danz il 19 Lug 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 Commenti
Ankitkumar Patel
Ankitkumar Patel il 19 Lug 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 il 19 Lug 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by