Text labeling with contourfm colorbar

4 visualizaciones (últimos 30 días)
George Lavidas
George Lavidas el 22 de En. de 2020
Comentada: George Lavidas el 22 de En. de 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.

Respuesta aceptada

Githin John
Githin John el 22 de En. de 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 comentario
George Lavidas
George Lavidas el 22 de En. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by