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

6 次查看(过去 30 天)
章立 胡
章立 胡 2022-11-2
评论: 章立 胡 2023-2-24
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读取如下:
请问如何解决。

采纳的回答

Varun
Varun 2023-2-22
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!