How to label datapoints in a boxplot?
Ältere Kommentare anzeigen
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!
Antworten (2)
Kishan Dhakan
am 30 Jun. 2021
0 Stimmen
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 Kommentare
Nuria Andreu
am 30 Jun. 2021
Sabrina Bitz
am 13 Mai 2022
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.
Kategorien
Mehr zu Exploration and Visualization finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

