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

조회 수: 14 (최근 30일)
Scott MacKenzie
Scott MacKenzie 2021년 4월 20일
편집: Scott MacKenzie 2021년 5월 12일
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에서 Labels and Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by