Box plot labels not working for hold on

조회 수: 19 (최근 30일)
Hannah Taylor
Hannah Taylor 2021년 2월 23일
답변: Hannah Taylor 2021년 2월 24일
Hello,
I'm trying to create a box plot from an array in a text file. However I'm having an issue with my x tick labels. They're only being shown for the third set of data. Any ideas?
(P.s. I'm fairly new to Matlab so sorry if my code is long winded, I know it could have been written in a much nicer way!!)
Thanks in advance
Tab = readtable("Validation.txt");
TABLE=table2array(Tab);
Data=TABLE(:,:);
X1= [1 2 3];
X2=[4 5 6];
X3=[7 8 9];
hold all
boxplot(Data(:,1:3),'notch', 'on','Colors',"r","Positions",X1,'Labels',{'1mm A','1mm B','1mm C'})
boxplot(Data(:,4:6),'notch','on','Colors',"b",'Positions',X2,'Labels',{'1.5mm A','1.5mm B','1.5mm C'})
boxplot(Data(:,7:9),'notch','on','Colors',"g",'Positions',X3,'Labels',{'3mm A','3mm B','3mm C'})
xlim([0 10]);
set(gca,'FontSize',10,'XTickLabelRotation',90)

채택된 답변

Hannah Taylor
Hannah Taylor 2021년 2월 24일
Managed to fix this (for anyone that stumbles across a similar issue in the future!). The issue was that the figure was only displaying three ticks (the final 3) and so when it went to assign tick labels, it only assigned them to the final three. I inserted the final line:
boxplot(Data(:,1:3),'notch', 'on','Colors',"r","Positions",X1)
boxplot(Data(:,4:6),'notch','on','Colors',"b",'Positions',X2)
boxplot(Data(:,7:9),'notch','on','Colors',"g",'Positions',X3)
xticklabels({'1mm A','1mm B','1mm C','1.5mm A','1.5mm B','1.5mm C','3mm A','3mm B','3mm C'})
set(gca,'xtick',1:9); %inserted this line!!
Which gave the plot 9 ticks, allowing all 9 tick labels to be displayed.

추가 답변 (1개)

randerss simil
randerss simil 2021년 2월 23일
편집: randerss simil 2021년 2월 23일
Tab = readtable("Validation.txt");
TABLE=table2array(Tab);
Data=TABLE(:,:);
X1= [1 2 3];
X2=[4 5 6];
X3=[7 8 9];
hold all
boxplot(Data(:,1:3),'notch', 'on','Colors',"r","Positions",X1)
boxplot(Data(:,4:6),'notch','on','Colors',"b",'Positions',X2)
boxplot(Data(:,7:9),'notch','on','Colors',"g",'Positions',X3)
xticklabels({'1mm A','1mm B','1mm C','1.5mm A','1.5mm B','1.5mm C','3mm A','3mm B','3mm C'})
xlim([0 10]);
set(gca,'FontSize',10,'XTickLabelRotation',90)
Try the above
  댓글 수: 3
randerss simil
randerss simil 2021년 2월 24일
편집: randerss simil 2021년 2월 24일
Tab = readtable("Validation.txt");
TABLE=table2array(Tab);
Data=TABLE(:,:);
X1= [1 2 3];
X2=[4 5 6];
X3=[7 8 9];
hold all
boxplot(Data(:,1:3),'notch', 'on','Colors',"r","Positions",X1);xticklabels({'1mm A','1mm B','1mm C'})
boxplot(Data(:,4:6),'notch','on','Colors',"b",'Positions',X2);xticklabels({'1.5mm A','1.5mm B','1.5mm C'})
boxplot(Data(:,7:9),'notch','on','Colors',"g",'Positions',X3);xticklabels({'3mm A','3mm B','3mm C'})
xlim([0 10]);
set(gca,'FontSize',10,'XTickLabelRotation',90)
Try the above again
Hannah Taylor
Hannah Taylor 2021년 2월 24일
still no luck! Looks like the first image again

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

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by