Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Adam Danz
Adam Danz le 19 Juil 2023
Modifié(e) : Adam Danz le 19 Juil 2023
FYI, I've removed the attachment. The function can be found on the File Exchange:
cbarf (author: @M MA).

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 19 Juil 2023
Modifié(e) : Adam Danz le 19 Juil 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 commentaires
Ankitkumar Patel
Ankitkumar Patel le 19 Juil 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 le 19 Juil 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by