Box plot labels not working for hold on

12 次查看(过去 30 天)
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