how to specify the X and Y ticklable?

5 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2018-9-6
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 个评论
Beatriz Sanchez
Beatriz Sanchez 2018-9-6
ok, now matlab show me the correct ticklabels but the Xticklabel appers spaced differently than Yticklabel :-/

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2018-9-6
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 个评论
Beatriz Sanchez
Beatriz Sanchez 2018-9-6
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 2018-9-6
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by