How to move the colorbar label to top position of the bar?

조회 수: 91 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 8월 7일
답변: AB 2025년 7월 14일
I need to change the colorbar label to the position showed in the attached image.
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
clims = [4 18];
imagesc(C,clims)
e=colorbar;
e.Label.String = 'amp';

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 8월 7일
편집: Dyuman Joshi 2023년 8월 7일
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
clims = [4 18];
imagesc(C,clims)
e=colorbar;
e.Label.String = 'amp';
%Adjust the position of the label
e.Label.VerticalAlignment = 'middle';
%The positioning, in the default unit, of the text label
%is corresponding to the values of colorbar
%x value is Middle of the colorbar i.e. 0.5
%y value is slightly above the top limit of colorbar
e.Label.Position = [0.5 clims(2)+0.75];
Edit - If you want to make the text horizontally aligned, change the rotation to 0 by using the command below
e.Label.Rotation = 0;

추가 답변 (1개)

AB
AB 2025년 7월 14일
There seems to be a hidden Title property on the ColorBar object that might be a better way to accomplish this. Just do
h = colorbar;
h.Title.String = 'amp';
Note that h.Title will not appear until set.

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by