How can I set the 'Xticks' to the bound of the colours in a colorbar?

1 回表示 (過去 30 日間)
Szabó-Takács Beáta
Szabó-Takács Beáta 2016 年 6 月 15 日
Dear All,
I would like to create a colorbar where the ticks are in the bound of colours. I tried to do it by the following way:
fig1=figure;
axis off
cmap=jet(6);
colormap(cmap)
caxis([1 6])
h=colorbar ('location',' Southoutside', 'XTick',[1 2 3 4 5 6], 'XTickLabel',{'0' '50' '100' '150' '200' '250'})
h.Limits = [1 6]
h.Label.String='P(mm/year)'
set(h, 'FontSize',14, 'FontWeight', 'bold');
But the range of ticks is wrong. I attached the result. How can I create a colorbar where the second tick (50) is between dark and pale blue, the third (100) is between pale blue and turquoise, the fourth (150) is between turquoise and green, the fifth (200) is between green and yellow and the sixth (250) is between yellow and orange?

採用された回答

Adam
Adam 2016 年 6 月 15 日
nTicks = 6;
range = 6 - 1;
inc = range / nTicks;
ticks = ( 0:nTicks ) * inc + 1;
Then set these as XTick
  1 件のコメント
Szabó-Takács Beáta
Szabó-Takács Beáta 2016 年 6 月 15 日
Thank you very mutch Adam for your help! It works correctly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePurple についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by