Boxplot how to make the box widths proportional to sample size

I would like to modify the box widths proportional to the sample size. Similar to the attached figure.
Can I do this with Matalb?
thanks

Answers (1)

There is no function in Matlab that does this natively, but you can write it from scratch.
If it is important to you that your code works on older Matlab releases you will have to make something with patch and line objects (see their documentation for help). For newer releases you can use the boxchart function. The boxplot function is in a toolbox, so that also has limited compatibility (although it is supported by older releases than those supporting boxchart).
The main idea would be to plot your boxes in a loop, 1 per iteration, in which you set the width yourself.

Categories

Asked:

on 21 Feb 2022

Answered:

Rik
on 21 Feb 2022

Community Treasure Hunt

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

Start Hunting!