Text labeling with contourfm colorbar

3 vues (au cours des 30 derniers jours)
George Lavidas
George Lavidas le 22 Jan 2020
Commenté : George Lavidas le 22 Jan 2020
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.

Réponse acceptée

Githin John
Githin John le 22 Jan 2020
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 commentaire
George Lavidas
George Lavidas le 22 Jan 2020
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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by