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!

Answers (2)

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 Comments

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!
Did you get it? I have the same question.

Sign in to comment.

Tom
Tom on 25 Dec 2024
Edited: Tom on 25 Dec 2024
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.

Products

Release

R2021a

Asked:

on 30 Jun 2021

Edited:

Tom
on 25 Dec 2024

Community Treasure Hunt

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

Start Hunting!