フィルターのクリア

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 Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by