Effacer les filtres
Effacer les filtres

箱型图绘制中多个箱型图无法居中排列在各个网格线上

6 vues (au cours des 30 derniers jours)
章立 胡
章立 胡 le 2 Nov 2022
Commenté : 章立 胡 le 24 Fév 2023
tbl = readtable('triple.xlsx');
order = {'LRBIx4','LRBIx5','LRBIx6','LRBIx7'};
tbl.name = categorical(tbl.name,order);
b = boxchart(tbl.name,tbl.PSNR,'GroupByColor',tbl.name,'linewidth',1.5,'BoxWidth',1);
legend
grid on;
box on;
结果如上,但是如果我去掉'GroupByColor'就能正常显示
tbl读取如下:
请问如何解决。

Réponse acceptée

Varun
Varun le 22 Fév 2023
Hello!
As per my understanding, you are trying to implement box plots of multiple colors in the same boxchart using the 'GroupByColor' option and noticing a shift in the box plots. This is because the GroupByColor feature expects another set of data to plot in the same label on the x-axis. While this isn’t easily apparent when using the same table column for both the x-axis and the grouping criteria, it is better showcased in this example (https://www.mathworks.com/help/matlab/ref/boxchart.html?searchHighlight=boxchart&s_tid=srchtitle_boxchart_1 ):
In this example, the variable ‘month’ is being used as the x-axis variable, while the grouping criteria is the variable ‘year’. In the latter months, data for months August to December does not exist for year 2016 and hence, the graph just leaves a gap for it. The data was expected but wasn’t found.
Boxcharts in MATLAB cannot have different coloured box plots per se if the data doesn’t need to be grouped.
A workaround to implement box plots of different colours without grouping can be found here: https://www.mathworks.com/matlabcentral/answers/1705595-color-each-boxplot-differently . However, the data will have to be restructured when switching to ‘boxplot’ from ‘boxchart’.
Hope this helps!
  1 commentaire
章立 胡
章立 胡 le 24 Fév 2023
Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Legend dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!