Text labeling with contourfm colorbar

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Colorbar 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by