Extracting Num Points from each box using boxchart
이전 댓글 표시
Hi,
I am using boxchart to create various box plots. When viewing the figure, there is a property for each box called Num Points, as shown in the image. Is there any way to extract this value?
Thanks in advance

답변 (1개)
How to get Num Points....
...From the data
The most efficient way to get the number of points that compose each box is from the data itself. Using the syntax boxchart(ydata), the number of points in each bin is the height of ydata. Using the syntax boxplot(xgroupdata,ydata), the number of points in each bin is the number of times each group value appears in xgroupdata. For example, using the data below, there are 9 points in group 1 and 16 points in group 9.
rng('default') % for reproducibility
groups = randi(9,1,100); % groups 1:9
y = rand(size(groups)); % random y data
% boxchart(groups,y)
groupCount = histcounts(groups,'BinMethod','integers')
groupID = unique(groups)
If your group values are not integers, you can use findgroups to convert them to integer values.
...From the datatip
If this is something you only need to do a few times and you do not need a programmatic approach, method #3 in this answer is easiest. Alternatively, you could use getDataTip from the file exchange. It extracts the datatip content and handles from a figure, axis, or an array of figures and axes in Matlab r2014 and later. A third alternative off the top of my head is to create a custom update function so that the NumPoints is extracted when the user presses the box.
댓글 수: 4
Ali Borhan-Azad
2022년 3월 15일
Ali Borhan-Azad
2022년 3월 15일
편집: Ali Borhan-Azad
2022년 3월 15일
Adam Danz
2022년 3월 15일
Well done with finding a solution to your follow-up question! You could also look into findgroups, perhaps something like,
[G,GID] = findgroups([xgroups, subcat])
Ali Borhan-Azad
2022년 3월 15일
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!