How to set colorbar tick labels between ticks

조회 수: 122 (최근 30일)
Fabrice Lambert
Fabrice Lambert 2019년 8월 9일
편집: Fabrice Lambert 2019년 8월 9일
Hi all,
The default setup for Matlab colorbar is to set the tick label just next to the tick (below, above, right of, left of). How do I set the label between two ticks? In the following example, I want 'Decrease', 'Slight Decrease', 'Slight Increase', and 'Increase' between the ticks, while 'No Change' stays below the tick:
Thanks!
ColorbarExample.PNG

채택된 답변

Neuropragmatist
Neuropragmatist 2019년 8월 9일
Does it matter if the ticks are moved as well?
figure('Position',[200 200 1000 200])
plot(0,0)
cc = colorbar('Location','SouthOutside');
cc.YTick = [0.125 0.375 0.5 0.625 0.875];
cc.YTickLabel = {'Decrease', 'Slight Decrease', 'No Change', 'Slight Increase', 'Increase'};
gives:
untitled.png
Otherwise you could remove the colorbar labels, and use 'text' with the units normalized and position new labels yourself, then they would be relative to the plot, not the colorbar which wouldn't be a perfect solution but might help you this once:
Hope this helps,
M.
  댓글 수: 1
Fabrice Lambert
Fabrice Lambert 2019년 8월 9일
편집: Fabrice Lambert 2019년 8월 9일
Hi Metioche,
That worked, I defined the contours and the ticks differently:
contourf(XX,YY,Prod,(-1:0.5:1))
cbar = colorbar('Southoutside','Ticks',[-0.8,-0.4,0,0.4,0.8],'TickLabels',{'Decrease','Slight Decrease','No Change','Slight Increase','Increase'});
Thanks,
Fabrice

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by