Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to fill boxplot with color

3,037 views
Skip to first unread message

Ian

unread,
Jan 5, 2011, 2:10:23 PM1/5/11
to
Hi,
I am looking to fill my 'notched' boxplot with different colors, one for the control group and one for the treated group.

I have found several ways to change 'colors' and 'groupcolor' however, this only effects the outline color of the box, I would like to change the fill color of the box & whisker plot.

Please help.

Tom Lane

unread,
Jan 6, 2011, 10:49:28 AM1/6/11
to

Ian, as you probably suspect there's no built-in way to do this. The box is
formed as a series of lines, and it contains no object with a color to fill
in.

Here's how I would do it. There's a relatively simple way to get the
coordinates of the boxes. You can loop over them and make patches with the
same coordinates. You can give those patches a color, and some transparency
so the median line will show through.

load carsmall
boxplot(MPG,Origin)
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),'y','FaceAlpha',.5);
end

-- Tom

Ian

unread,
Jan 15, 2011, 4:20:18 PM1/15/11
to
"Tom Lane" <tl...@mathworks.nospam.com> wrote in message <ig4oa8$d8a$1...@fred.mathworks.com>...

Thanks for the advice tom! That code above works perfectly :)

hermann c

unread,
Jan 27, 2011, 9:18:48 AM1/27/11
to
On 15 jan, 22:20, "Ian " <isha...@uic.edu> wrote:
> "Tom Lane" <tl...@mathworks.nospam.com> wrote in message <ig4oa8$d8...@fred.mathworks.com>...

Excellent
Thanks

Mehri Mehrnia

unread,
Nov 7, 2021, 4:01:41 PM11/7/21
to
The drawback of this that you will loose median line
0 new messages