title string on vertical colorbar

I want to put a colorbar to the right of a plot; fortunately, MATLAB wants to do that too, so a plain call to colorbar works. However, I'd also like to put a readable title on the colorbar to identify the plotted variable & its units. I tried this
h = colorbar;
set(get(h,'title'),'string','ISCCP Daytime Sc Amount (%)');
MATLAB wants to put this above the colorbar (!) where it runs into the plot title. I can rotate the text
h = colorbar;
set(get(h,'title'),'string','ISCCP Daytime Sc Amount (%)','Rotation',90.0);
but it's still centered up above the vertical colorbar. Trying to calculate a position for it in colorbar-relative coordinates is a real pain. Is there another way to correctly position this metadata alongside the colorbar?

1 件のコメント

KEVIIN CHRISTOPHER CORDOVIZ
KEVIIN CHRISTOPHER CORDOVIZ 2018 年 1 月 30 日
編集済み: Rik 2020 年 2 月 18 日
Simple Solution for this.
h = colorbar;
set(get(h,'label'),'string','ISCCP Daytime Sc Amount (%)');
That way, it will no longer be on top of the colorbar but beside it. :)

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

回答 (2 件)

Patrick Kalita
Patrick Kalita 2011 年 7 月 8 日

49 投票

This is kind of hack, but how about this:
h = colorbar;
ylabel(h, 'foo')

6 件のコメント

Igor
Igor 2012 年 11 月 9 日
simplicity is the key of prosperity! perfect answer. good job Patrick
Suene
Suene 2015 年 11 月 18 日
great
noone
noone 2018 年 4 月 4 日
This is genius!!!
Roy Goodman
Roy Goodman 2019 年 5 月 20 日
This answer is great, but I have one issue.
I have set all labeling of figures to default to using latex as the intepreter. When I follow this example the ylabel does not show up in latex unlesss I do
ylabel(h, 'foo', 'intepreter', 'latex');
I don't want to have to do this manually, so I added
set(groot,'DefaultColorbarYLabelInterpreter','latex')
to my startup.m file. This returns an error
Error using matlab.ui.Root/set
There is no YLabelInterpreter property on the ColorBar class.
How do I set the default then, I know that there is a ColorbarTickLabelInterpreter class.
Daniyal Altaf Baloch
Daniyal Altaf Baloch 2020 年 2 月 7 日
You saved us. Good answer
Brice Arthur Azangue
Brice Arthur Azangue 2023 年 6 月 12 日
thanks for this code

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

Sara Soufsaf
Sara Soufsaf 2022 年 4 月 9 日

1 投票

To update Patrick Kalita's answer
h = colorbar;
title(h, 'foo')

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

質問済み:

2011 年 7 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by