Creating a colorbar in Matlab

17 vues (au cours des 30 derniers jours)
Lavenia
Lavenia le 14 Fév 2024
Commenté : Lavenia le 14 Fév 2024
Im new to understanding Matlab and i have a two part question.
1. Is this colorbar automatic colors? As in Matlab picks its default colours? Because i do not choose colours anyhere, and just type these two commands in and i get a blue/yellow/green colour on the figure. What does cb stand for?
colorbar;
cb = colorbar;
2. Is there a way to create a manual colour bar using these colours? #0192bf, #41abce, #ffff00, #ffff41, #ffff7f. Im making a contour plot using contourf
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 14 Fév 2024
"Is this colorbar automatic colors?"
The colorbar just displays the bar which shows the color scale of the figure.
"As in Matlab picks its default colours?"
Yes.
"What does cb stand for?"
cb is the handle to the colorbar object.
"Is there a way to create a manual colour bar using these colours? #0192bf, #41abce, #ffff00, #ffff41, #ffff7f. Im making a contour plot using contourf "
See the section on making a custom colormap on this page - colormap.
There are loads of other questions on this forum with examples of making custom colormaps for a figure. Go through them.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 14 Fév 2024
"Is this colorbar automatic colors? As in Matlab picks its default colours?"
Yes. The default colormap is described here:
"What does cb stand for?"
I guess that CB stands for "ColorBar". But the name of that variable is much less important than what it is: a COLORBAR object:
"Is there a way to create a manual colour bar using these colours? #0192bf, #41abce, #ffff00, #ffff41, #ffff7f."
S = ['#0192bf'; '#41abce'; '#ffff00'; '#ffff41'; '#ffff7f'];
M = sscanf(S.','#%2x%2x%2x',[3,Inf]).' ./ 255;
Z = peaks;
contourf(Z)
colormap(M)
colorbar()
  1 commentaire
Lavenia
Lavenia le 14 Fév 2024
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by