Box Plot with Percentiles Known
7 views (last 30 days)
Show older comments
I want to plot accuracy measures for an environmental variable, using the box plot approach. I have the error values / bounds for the 5, 25, 75, and 95th percentiles. All I want to do is show these error bounds using a box plot. I don't want box plot to calculate anything ... just produce the plot. Is there some way to do this in MATLAB ??
2 Comments
Accepted Answer
Oleg Komarov
on 10 Mar 2012
One approach is to draw the boxplot and then adjust it:
Say you have data
data = rand(100,2);
% Your 5 (1st row), 25, 75, 95 (last row) stats
s = [0.3 0.2; 0.4 0.42; 0.8 0.79; .89 .88];
% Calculate boxplot retaining handles
h = boxplot(data);
% Modify upper whisker's length
set(h(1,:),{'Ydata'},num2cell(s(end-1:end,:),1)')
% Modify lower whisker's length
set(h(2,:),{'Ydata'},num2cell(s(2:-1:1,:),1)')
% Modify upper whisker's endbar
set(h(3,:),{'Ydata'},num2cell(s([end end],:),1)')
% Modify lower whisker's endbar
set(h(4,:),{'Ydata'},num2cell(s([1 1],:),1)')
% Modify body
set(h(5,:),{'Ydata'},num2cell(s([2 3 3 2 2],:),1)')
% Median? (nothing specified, just invisible)
set(h(6,:),{'Visible'},{'off'})
% Outliers? (set the old ones to off and draw new ones)
set(h(7,:),{'Visible'},{'off'})
hold on
plot(1,.95,'+r',2,.1,'+r')
You could encapsulate these commands in a function or you could write a personalized boxplot, which way is best depends on the use you need of it.
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!