Creating a colorbar in Matlab

17 visualizaciones (últimos 30 días)
Lavenia
Lavenia el 14 de Feb. de 2024
Comentada: Lavenia el 14 de Feb. de 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 comentario
Dyuman Joshi
Dyuman Joshi el 14 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 14 de Feb. de 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()

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by