Box plot labels not working for hold on

6 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by