How to get position of single box in grouped box chart on x-axis?
조회 수: 21 (최근 30일)
이전 댓글 표시
I would like to get the position of each single box on the x-axis I created with boxchart(). But the box chart object is grouped, so when I type XAxis.Categories I only get the two grouping categories even though it's actually 6 boxes.
댓글 수: 0
답변 (1개)
Scott MacKenzie
2021년 5월 11일
편집: Scott MacKenzie
2021년 5월 11일
The use of grouped data changes the XData type to categorical for the BoxChart. Plus, there doesn't seem to be any BoxChart property that gives the x position of the group or the x-offset of the boxes within a group. I determined that the actual x positions of the groups are 1, 2, 3, etc., as they would be if the data were not categorical. Knowing this, I concocted a scheme to compute the x-position of each box, so that text annotations (or whatever) can be added. See below. This can probably be vectorized in some way, but I thought it might useful to post this in the present form.
set(groot, 'defaultTextHorizontalAlignment', 'center');
m = 3; % number of boxes per group
xGap = 1 / m;
grp = 1; % x position for 1st group
text(grp-xGap, 30, 'a1');
text(grp, 30, 'a2');
text(grp+xGap, 30, 'a3');
grp = 2; % x position for 2nd group
text(grp-xGap, 30, 'b1');
text(grp, 30, 'b2');
text(grp+xGap, 30, 'b3');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!