Azzera filtri
Azzera filtri

how to specify the X and Y ticklable?

5 visualizzazioni (ultimi 30 giorni)
Hi, so I'm trying to specify the Xticklable and Yticklable on a contourf. Unfortunately when I give the vector that I want to see, matlab repeat those lables on the axes. This is the code I'm using:
vec=[-180 -36 0 36 180]
for i=1:3
figure(1)
subplot(1,3,i)
if i==1
contourf(nzro_mean1)
elseif i==2
contourf(nzro_mean2)
elseif i==3
contourf(nzro_mean3)
end
axis square
set(gca,'XTickLabel',{vec})
set(gca,'YTickLabel',{vec})
title(['Especie ',num2str(i)])
colorbar('southoutside')
end
and the images below is how appers. Does anybody knows what is happening and how can I solve this? note: nzro_mean1, 2 and 3 is a matrix 5x5

Risposta accettata

Star Strider
Star Strider il 6 Set 2018
Replace your current set calls:
set(gca,'XTickLabel',{vec})
set(gca,'YTickLabel',{vec})
with these assignments:
xt = get(gca, 'XTick');
xtv = linspace(min(xt), max(xt), numel(vec));
yt = get(gca, 'YTick');
ytv = linspace(min(yt), max(yt), numel(vec));
set(gca, 'XTick',xtv, 'XTickLabel',vec, 'YTick',ytv, 'YTickLabel',vec)
That should work.
  4 Commenti
Beatriz Sanchez
Beatriz Sanchez il 6 Set 2018
ok, now matlab show me the correct ticklabels but the Xticklabel appers spaced differently than Yticklabel :-/
Star Strider
Star Strider il 6 Set 2018
Try using:
axis equal
instead.

Accedi per commentare.

Più risposte (1)

dpb
dpb il 6 Set 2018
X,YTick and X,YTickLabel are integrally coupled together -- you must label every tick with a label (or a blank string if don't want anything shown at a particular location and you also must not have more tick labels than ticks.
If there are more ticks than you pass labels, then it starts over with the list from the beginning until all ticks are labelled.
If you pass more strings than are ticks set, the last ones are ignored; it doesn't make more ticks to display all the ones you passed.
IOW, you must first set the tick values and number to the locations you want labelled; THEN set the tick labels for each as you wish.
  2 Commenti
Beatriz Sanchez
Beatriz Sanchez il 6 Set 2018
I don't understand. I don't have more ticks than labels. I have 5 labels on each axes and the contourf is a 5x5 matrix. How do I set the tick values and number to the locations I want labelled?
dpb
dpb il 6 Set 2018
The figure is too little to read but there are 10 divisions or 9 ticks on each axis, not five.
You have to decide where and how many ticks you want and set the number and location.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by