From: Mohammad on
Is there any way to change the colors in a bar or two of the stacked bar graph without affecting the rest of the bars, in example; I have the matrix a where
a= a= [1 2 5 3; 2 3 6 1; 3 5 6 4];
and I would like to plot is as stacked bar, so
bar(a,'stack');
which creates 3 bars having 4 colored bits in each (dark blue, blue, orange and brown)
if I want to change the orange for instance to red in the second bar only, how can I do this?
Thanks
From: Walter Roberson on
Mohammad wrote:
> Is there any way to change the colors in a bar or two of the stacked bar
> graph without affecting the rest of the bars, in example; I have the
> matrix a where a= a= [1 2 5 3; 2 3 6 1; 3 5 6 4];
> and I would like to plot is as stacked bar, so
> bar(a,'stack');
> which creates 3 bars having 4 colored bits in each (dark blue, blue,
> orange and brown) if I want to change the orange for instance to red in
> the second bar only, how can I do this?

It is possible in theory, a bit ugly in practice.

t = bar(a,'stack')

will set t to be an array of 4 barseries objects -- one for each _band_ (not
one for each _bar_). Each of the barseries objects has one Child which is a
patch() object. Each of the patch objects has a CData property which controls
the coloring.

I wouldn't enjoy working through the details of how the patch is constructed,
but it wouldn't be too terrible.