How to label datapoints in a boxplot?

조회 수: 34 (최근 30일)
Nuria Andreu
Nuria Andreu 2021년 6월 30일
편집: Tom 2024년 12월 25일 4:27
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
Kishan Dhakan 2021년 6월 30일
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
Nuria Andreu 2021년 6월 30일
Hello, but how can I dispay the values into the boxplot? I want it to look like this image with median values, outliers, etc:
but this is the result I am getting right now
thank you!
Sabrina Bitz
Sabrina Bitz 2022년 5월 13일
Did you get it? I have the same question.

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


Tom
Tom 대략 21시간 전
편집: Tom 대략 21시간 전
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.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by