Creating a colorbar in Matlab

21 次查看(过去 30 天)
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 个评论
Dyuman Joshi
Dyuman Joshi 2024-2-14
"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.

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2024-2-14
"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()

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by