Find the number of red marks in box plot

19 ビュー (過去 30 日間)
NA
NA 2021 年 12 月 12 日
編集済み: Chris 2021 年 12 月 12 日
I have the box plot like this. How can I find the number of the red marks?
T = [1;-1;0.5;-0.5;0.75;-0.75;-6;-7;4;3];
h = boxplot(T,'Labels',{'1'});

採用された回答

Chris
Chris 2021 年 12 月 12 日
編集済み: Chris 2021 年 12 月 12 日
One method, which may not necessarily correlate to a boxplot in all situations (but probably works for the default boxplot), is to use isoutlier:
T = [1;-1;0.5;-0.5;0.75;-0.75;-6;-7;4;3];
outliers = isoutlier(T);
numOutliers = sum(outliers)
numOutliers = 2
h = boxplot(T,'Labels',{'1'});
If you need to be sure you have the exact count in the boxplot, you can get the data in the image and drill down to find the outliers:
ax = gca; % Get current axes
bxplt = ax.Children; % The boxplot
plts = bxplt.Children % Individual plots that make up the boxplot.
plts =
7×1 Line array: Line (Outliers) Line (Median) Line (Box) Line (Lower Adjacent Value) Line (Upper Adjacent Value) Line (Lower Whisker) Line (Upper Whisker)
% plts(1) holds the outliers
numRedMarks = numel(plts(1).YData)
numRedMarks = 2
% XData or YData -- points that make up the Outliers plot
To programmatically find the plots of outliers (in the event that you have more than one box):
idxs = find(strcmp({plts.Tag},'Outliers'));
outlierCell = {plts(idxs).YData}
outlierCell = 1×1 cell array
{[-7 -6]}
numMarksFirstPlot = numel(outlierCell{1})
numMarksFirstPlot = 2

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by