student
student

Reputation: 101

labels on imagesc plot: why they are duplicated?

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.

output from my code

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

Answers (1)

Adriaan
Adriaan

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);

enter image description here

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

Related Questions