how to fill boxplot with color

  • Follow


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.
0
Reply Ian 1/5/2011 7:10:23 PM

> 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.

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 

0
Reply Tom 1/6/2011 3:49:28 PM


"Tom Lane" <tlane@mathworks.nospam.com> wrote in message <ig4oa8$d8a$1@fred.mathworks.com>...
> > 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.
> 
> 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 

Thanks for the advice tom!  That code above works perfectly :)
0
Reply Ian 1/15/2011 9:20:18 PM

On 15 jan, 22:20, "Ian " <isha...@uic.edu> wrote:
> "Tom Lane" <tl...@mathworks.nospam.com> wrote in message <ig4oa8$d8...@fr=
ed.mathworks.com>...
> > > 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 chang=
e the
> > > fill color of the box & whisker plot.
>
> > Ian, as you probably suspect there's no built-in way to do this. The bo=
x 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 transpar=
ency
> > so the median line will show through.
>
> > =A0load carsmall
> > =A0boxplot(MPG,Origin)
> > =A0h =3D findobj(gca,'Tag','Box');
> > =A0for j=3D1:length(h)
> > =A0 =A0 patch(get(h(j),'XData'),get(h(j),'YData'),'y','FaceAlpha',.5);
> > =A0end
>
> > -- Tom
>
> Thanks for the advice tom! =A0That code above works perfectly :)

Excellent
Thanks
0
Reply hermann 1/27/2011 2:18:48 PM

3 Replies
1093 Views

(page loaded in 0.002 seconds)

Similiar Articles:













7/20/2012 4:06:59 PM


Reply: