Boxplot Label Numberical Organization

2 views (last 30 days)
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)?

Accepted Answer

Aaditya Pore
Aaditya Pore on 12 Jul 2022
Found answer in this forum.

More Answers (1)

dpb
dpb on 11 Jul 2022
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 Comment
Aaditya Pore
Aaditya Pore on 12 Jul 2022
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!

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!