箱型图绘制中多个箱型图无法居中排列在各个网格线上
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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读取如下:
请问如何解决。
0 comentarios
Respuesta aceptada
Varun
el 22 de Feb. de 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!
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!