Can boxchart create a box plot with grid lines behind the boxes?

8 次查看(过去 30 天)
I'm trying to use boxchart create a box plot with y-axis grid lines. Obviously, I want the grid lines positioned behind the boxes, as they are for bars in a bar chart. But they appear in front of the boxes -- very unsightly. It seems this is due to the default alpha (0.2) for the box face color. So, I tried setting alpha to 1. The problem then is that the box edges and median lines are lost -- also unsightly. I'd like to set the box line or edge, but there are no such properties for boxchart. So, I'm stuck with the last chart below. Any suggestions on how to create a box plot like the second chart below, except with the grid lines behind the boxes?
y = randi(100,25,2);
clr = [.7 .85 .9];
tiledlayout('flow');
nexttile;
bar(mean(y), 'facecolor', clr);
ax = gca;
ax.YGrid = 'on';
nexttile;
boxchart(y);
ax = gca;
ax.YGrid = 'on';
nexttile;
boxchart(y, 'boxfacecolor', clr);
ax = gca;
ax.YGrid = 'on';
nexttile;
b = boxchart(y, 'boxfacecolor', clr, 'boxfacealpha', 1);
ax = gca;
ax.YGrid = 'on';

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by