필터 지우기
필터 지우기

How can I display min and max in the colorbar?

조회 수: 88 (최근 30일)
Hung Jr Chen
Hung Jr Chen 2016년 5월 1일
답변: gwoo 2018년 10월 26일
Hi,
I would like to display max and min value on my colorbar.
How can I do it?
In my plot it only displays 0.01, 0.02, 0.03...
I want to display max and min also on the colorbar.
Thanks.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 5월 1일
Are you using R2014a or earlier, or are you using R2015b or later?

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 1일
h=colorbar
t=get(h,'Limits');
set(h,'Ticks',linspace(t(1),t(2),5)
  댓글 수: 2
Hung Jr Chen
Hung Jr Chen 2016년 5월 2일
Hi Professor Abdelmalek,
Thanks so much for your help :D It really works :D
Hmm...I would like to round my colorbar values to 2 decimal places, is it possible?
Like in my figure, it has 4 dicimal places, 0.0372, I would like to display to 0.04 only.
I don't know how to do that :S
I try:
but failed.
Walter Roberson
Walter Roberson 2016년 5월 2일
You need to also set the TickLabels properties.
Could you confirm that you are using R2014b or later? It appears likely you are as Ticks was not a property of colorbars from R2014a and before.

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

추가 답변 (1개)

gwoo
gwoo 2018년 10월 26일
You can also do the following and keep the automatically selected tick marks.
hColorbar = colorbar;
set(hColorbar, 'Ticks', sort([hColorbar.Limits, hColorbar.Ticks]))
This simply adds the limits to the tick labels and sorts them in order so they don't error out.
If you want them to be the same display precision (digits shown) as the others, you can do the typical:
round(0.00532 * 1000) / 1000
Obviously change the 1000 to whatever value you need to get whatever digit you need to round off to the one's place value for the rounding function. The /1000 gets it back in the original units.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by