Text labeling with contourfm colorbar

4 ビュー (過去 30 日間)
George Lavidas
George Lavidas 2020 年 1 月 22 日
コメント済み: George Lavidas 2020 年 1 月 22 日
Hello All,
I have been trying to label a colorbar with text with a figure resulted from the contourfm, while I do have some success I cannot get the first text value to appear.
with a simple contourf it does show up but when i plot with contourfm then it misses values.
What I am after is for the colorbar to include all legend_Names2, staring with the first one on the far left.
I attach the following working code snippet
Data= magic(2); % mock data
legend_Names2={'Opt1','Opt2','Opt3','Opt4'}; % mock legend strings
%
R = georasterref('RasterSize', size(Data),'Latlim',[30 31], 'Lonlim', [2 3]);
contourfm(double(Data),R,'edgecolor','none')
colormap(flipud(jet(max(max(Data)))));
cbh=colorbar('southoutside');
cbh.XTick = [floor(min(xlim(cbh))):1:ceil(max(xlim(cbh)))]; % create Colobar ticks incrementaly by 1
cbh.TickLabels=legend_Names2;
test_controufm.png
Thank you all in advance.

採用された回答

Githin John
Githin John 2020 年 1 月 22 日
The value of floor(min(xlim(cbh))) evaluates to 1. The min value of the colorbar is 1.25. So the Tick for 1 is outside the colorbar and hence not visible.
Try
cbh.XTick = linspace(min(xlim(cbh)),ceil(max(xlim(cbh))),4);
or something similar.
  1 件のコメント
George Lavidas
George Lavidas 2020 年 1 月 22 日
Hello John,
Thank you very much, it works.
But if i may i have only a small question, just to clear it in my mind.
The matrix i have starts from 1 and that is why i used the floor() function, however you are totally right that the xbh lim is 1.25.
But in any case thank you very much, for the swift response.
Kind regards,
George

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by