Boxplot Label Numberical Organization

조회 수: 3 (최근 30일)
Aaditya Pore
Aaditya Pore 2022년 7월 11일
답변: Aaditya Pore 2022년 7월 12일
I am trying to graph multiple boxplots on a figure that have varying x values. I am inserting these labels into the boxplot function like so:
b = boxplot(ErrorPlot, 'Labels', weight);
However, I face an issue when the labels vary in distance. When graphing a set of labels, like seen in the image, the boxplots are equidistant regardless of what their labels say. Is it possible to ensure that these boxplots are graphed with a distance matching their label value (i.e. 10 and 20 are only 1/10th as far from each other as 100 and 200 are)?

채택된 답변

Aaditya Pore
Aaditya Pore 2022년 7월 12일
Found answer in this forum.

추가 답변 (1개)

dpb
dpb 2022년 7월 11일
Not an option w/ builtin boxplot, sorry.
You can make it work with the alternate boxchart function, but the large scale factor will probably end up with the boxes only being vertical lines as the spacing between the axis values is almost all white space.
I tried
x=randi(20,[20,4]);
g=[10 20 100 200].*ones(size(x));
hBC=boxchart(g(:),x(:));
with just a subset of your x values above -- it was less than satisfactory, methinks --
There is not an optional input to let one set the width of the boxes independently; whether one could go "handle-diving" and uncover the pieces and modify them or not I didn't explore.
  댓글 수: 1
Aaditya Pore
Aaditya Pore 2022년 7월 12일
Thanks for the response! I spent some more time looking and found that the boxplot function has a 'Positions' modifier (not in the documentation for some reason?). Anyway, running this code
boxplot(ErrorPlot, 'Positions', weight, 'Labels', weight);
got the results I was looking for. An image of a sample boxplot is attached. Thanks again!

댓글을 달려면 로그인하십시오.

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by