Reputation: 101
I try to make a labelled plot using imagesc
, with labels on the tick-axes, but I get two times as many labels as needed. What I am doing wrong? I tried both R2009B and R2017A.
Below is my code:
test_data = rand(5,5);
[RHO,PVAL_spearman] = corr(test_data,'Type','Spearman');
figure;
imagesc(RHO);
labelNames = {'item1','item2','item3','item4','item5'};
set(gca,'XTickLabel',labelNames);
set(gca,'YTickLabel',labelNames);
Upvotes: 0
Views: 227
Reputation: 18177
Apparently the default number of ticks on plots is 11, so you simply need to change the amount of ticks using the set(gca,'XTick',N)
property:
N = 5;
test_data = rand(N);
[RHO,PVAL_spearman] = corr(test_data,'Type','Spearman');
figure;
imagesc(RHO);
labelNames = {'item1','item2','item3','item4','item5'};
set(gca,'XTick',1:N);
set(gca,'YTick',1:N);
set(gca,'XTickLabel',labelNames);
set(gca,'YTickLabel',labelNames);
When specifying less than 11 label names MATLAB simply starts again at the first, until it has placed 11 labels, and when you provide more than 11, MATLAB ignores the labels beyond place 11.
Upvotes: 1