Christian Klumpp
Christian Klumpp

Reputation: 3

How to add line (manual min/max allowed value) to boxplot

I'm trying out to visualize some measurement data in a boxplot using the: boxplot(x,g) command in MATLAB. There's a manual giving a minimum and maximum allowed value. How can I add this value to the boxplot like in the painted screenshot below?

How it should look

Upvotes: 0

Views: 467

Answers (1)

EBH
EBH

Reputation: 10440

You can do the following (after you use boxplot):

max_bounds = [2 3 2]; % set the maximum bound by category
min_bounds = [-1 -2 -1]; % set the minimum bound by category
x = repmat(1:numel(max_bounds),[2 1]); % make x values for all categories
x = bsxfun(@plus,x,[-0.1; 0.1]); % make the lines in length of 0.2
hold on
% plot it all:
plot(x,repmat(min_bounds,[2 1]),'r',x,repmat(max_bounds,[2 1]),'r')

boxplot

Upvotes: 2

Related Questions