How to label datapoints in a boxplot?
古いコメントを表示
Hello! I have a boxplot with 3 subplots in it. I want to display each median, outlier, whisker, etc in my figure. I do not want to use a text format because I want to use the same code for different CSV files. The CSV files I will use later on have different medians, outliers, etc.
Hope anyone can help me
Thank yo!
回答 (2 件)
Kishan Dhakan
2021 年 6 月 30 日
0 投票
To modify graphics properties of a box plot component, use findobj with the Tag property to find the component's handle. Tag values for box plot components depend on parameter settings, and are listed in the following table.
Parameter SettingsTag Values
All settings
- 'Box'
- 'Outliers'
When 'PlotStyle' is 'traditional'
- 'Median'
- 'Upper Whisker'
- 'Lower Whisker'
- 'Upper Adjacent Value'
- 'Lower Adjacent Value'
When 'PlotStyle' is 'compact'
- 'Whisker'
- 'MedianOuter'
- 'MedianInner'
When 'Notch' is 'marker'
- 'NotchLo'
- 'NotchHi'
2 件のコメント
Nuria Andreu
2021 年 6 月 30 日
Sabrina Bitz
2022 年 5 月 13 日
Did you get it? I have the same question.
I found a way to brute-force it with the text function. The example below is for the percentiles only. I didn't try labeling outliers.
The variable i is used to call each dataset (I don't know how you organized your data) and also used to place the labels in the first, second, third, etc. columns. I nudge the label a bit (0.1) to right of center of each column, and a bit (5) above each line.
First you need to make your boxplot, and then:
for i = 1:3
switch i
case 1; Data = Thirties;
case 2; Data = Sixties;
case 3; Data = Nineties;
otherwise; Data = [];
end
point = quantile(Data,0.25); text(i+0.1,point+5,num2str(point,'%.0f')); % 25 percentile
point = quantile(Data,0.50); text(i+0.1,point+5,num2str(point,'%.0f')); % median
point = quantile(Data,0.75); text(i+0.1,point+5,num2str(point,'%.0f')); % 75 percentile
point = quantile(Data,0.75)+1.5*iqr(Data); text(i+0.1,point+5,num2str(point,'%.0f')); % upper whisker
point = quantile(Data,0.25)-1.5*iqr(Data); text(i+0.1,point+5,num2str(point,'%.0f')); % lower whisker
end
Good luck to others who stumble on this.
カテゴリ
ヘルプ センター および File Exchange で Exploration and Visualization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

