필터 지우기
필터 지우기

how to specify the X and Y ticklable?

조회 수: 5 (최근 30일)
Beatriz Sanchez
Beatriz Sanchez 2018년 9월 6일
댓글: dpb 2018년 9월 6일
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
  댓글 수: 1
madhan ravi
madhan ravi 2018년 9월 6일
upload nzro_mean1 and the other two datas to test

댓글을 달려면 로그인하십시오.

채택된 답변

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 :-/
Star Strider
Star Strider 2018년 9월 6일
Try using:
axis equal
instead.

댓글을 달려면 로그인하십시오.

추가 답변 (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