how to specify the X and Y ticklable?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195352/image.png)
1 Commento
Risposta accettata
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
Più risposte (1)
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
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.
Vedere anche
Categorie
Scopri di più su Axis Labels in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!