Box plot labels not working for hold on

7 vues (au cours des 30 derniers jours)
Hannah Taylor
Hannah Taylor le 23 Fév 2021
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)

Réponse acceptée

Hannah Taylor
Hannah Taylor le 24 Fév 2021
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.

Plus de réponses (1)

randerss simil
randerss simil le 23 Fév 2021
Modifié(e) : randerss simil le 23 Fév 2021
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 commentaires
randerss simil
randerss simil le 24 Fév 2021
Modifié(e) : randerss simil le 24 Fév 2021
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 le 24 Fév 2021
still no luck! Looks like the first image again

Connectez-vous pour commenter.

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by