title string on vertical colorbar

조회 수: 210 (최근 30일)
Leslie
Leslie 2011년 7월 8일
댓글: Brice Arthur Azangue 2023년 6월 12일
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일
This is kind of hack, but how about this:
h = colorbar;
ylabel(h, 'foo')
  댓글 수: 6
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일
To update Patrick Kalita's answer
h = colorbar;
title(h, 'foo')

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by