How do I position a label below a colorbar?

242 ビュー (過去 30 日間)
NA
NA 2020 年 8 月 21 日
コメント済み: Priyank Pathak 2022 年 9 月 22 日
Is there a way to add a label below a colorbar, as shown in the pic?
I am able to add a label (title) on top of the colorbar, though I am unsure how to position 'Label2' at the bottom of the colorbar so that it uniformly reflects 'Label1', despite having to adjust clims.
plot(1, 1);
c1 = colorbar;
c1.Title.String = 'Label1';
str = 'Label2';
set(get(c1, 'xlabel'), 'string', str, 'rotation', 0);
  2 件のコメント
Priyank Pathak
Priyank Pathak 2022 年 9 月 22 日
@dpb how can we label at top of colorbar?
Priyank Pathak
Priyank Pathak 2022 年 9 月 22 日
@dpb, how is it possible to make label at top of colorbar and height(colorbar and label ) and data plot height will be matched?

サインインしてコメントする。

採用された回答

dpb
dpb 2020 年 8 月 21 日
編集済み: dpb 2020 年 8 月 21 日
You're almost there...
hCB=colorbar;
hCB.Title.String='Title';
set(hCB.XLabel,{'String','Rotation','Position'},{'XLabel',0,[0.5 -0.01]})
That MathWorks hides all the useful properties is maddening, agreed.
Unfortunately, in colorbar, they also aliased the handles for XLabel, YLabel, and Label to the same object so one is limited to just the two. Anything else one would need to add would have to be an additional text or annotation object.
NB: The above uses an arbitrary position for the y position; another issue is that the title is in figure coordinates in normalized units of figure scaling while the label is in colorbar axis data units.
>> hCB.Title.String='Title'
hCB =
ColorBar (XLabel) with properties:
Location: 'eastoutside'
Limits: [0 1.00]
FontSize: 9.00
Position: [0.82 0.11 0.04 0.82]
Units: 'normalized'
Show all properties
>>
>> hCB.XLabel
ans =
Text (XLabel) with properties:
String: 'XLabel'
FontSize: 9.00
FontWeight: 'normal'
FontName: 'Helvetica'
Color: [0.15 0.15 0.15]
HorizontalAlignment: 'center'
Position: [0.50 -0.01 0]
Units: 'data'
Show all properties
>>
  1 件のコメント
NA
NA 2020 年 8 月 21 日
Thank you very much! It's so much clearer now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColorbar についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by