Boxplot for both x and y axis with different box widths.

조회 수: 50 (최근 30일)
Gechang Cao
Gechang Cao 2021년 4월 30일
댓글: Benjamin Kraus 2024년 8월 19일
How can we make a boxplot like the one below for both x and y data (the box widths of each group that are x-data related are different). I tried boxplot(X,Y, group) but it did not work.
boxplot for x- and y-data
  댓글 수: 4
Adam Danz
Adam Danz 2021년 4월 30일
편집: Adam Danz 2021년 4월 30일
I missed that since BoxWidth is not mentioned on the documentation page for boxchart, however it is listed in the properties page.
Thanks, Benjamin.
Gechang Cao
Gechang Cao 2021년 5월 1일
Thanks for your nice suggestions! boxchart works

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

채택된 답변

Benjamin Kraus
Benjamin Kraus 2021년 4월 30일
편집: Benjamin Kraus 2021년 4월 30일
The boxplot command creates a group of lines, so if you wanted to adjust the box widths you would need to manually adjust the XData properties on each line to move them to the desired locations.
The better alternative is to use the new boxchart command. The object created by the the boxchart command has a BoxWidth property, but I suspect you won't need it, because even when you specify x values, the boxes created by the boxchart command have uniform widths.
boxchart(randn(1000,1), 'BoxWidth', 0.3);
or
boxchart(randi(10,1000,1),randn(1000,1));
  댓글 수: 4
Adam Danz
Adam Danz 2021년 4월 30일
Thanks for the explanation, Benjamin.
I wonder what the logic is in converting numeric inputs to categorical under one syntax but not the other.
Gechang Cao
Gechang Cao 2021년 5월 1일
Thank you very much! Cool, the box widths now are controlled by some numbers. I tried some means but did not make it. The locations of x-data are also controlled by the real values not by even distance. Thanks a lot! This is really cool!!

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

추가 답변 (1개)

markus tripolt
markus tripolt 2024년 8월 18일
Hi all,
I have a additional question. Is there a function to set the box width according to the number of data points automatecally, or is the only way to calc the percentage per hand typ it to the width vector?
Thanks Markus
  댓글 수: 1
Benjamin Kraus
Benjamin Kraus 2024년 8월 19일
@markus tripolt: If you have a new question, your best bet is to post a new question to MATLAB Answers, rather than adding an "answer" to an existing question.
There is no method to automatically set the box width based on the number of data points. I'm not sure how you would use the number of data points to calculate the box widths.
If you post a new question, can you clarify how you want to convert the "number of data points" into the box width"? In addition, please clarify whether you are referring to boxchart or boxplot, because the answers will be very different between the two.

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by