简体   繁体   中英

change color to bar plot Matlab

I have the matrix A and I make a barplot

A = rand(15,9);
h = bar(A);

now I would like to color each group of bars (each row of A) according to the colormap "colorset" defined below

colorset = [0   0   1;...
1   0   0;...
0   1   0;...
0   0   0.172413793103448;...
1   0.103448275862069   0.724137931034483;...
1   0.827586206896552   0;...
0   0.344827586206897   0;...
0.517241379310345   0.517241379310345   1;...
0.620689655172414   0.310344827586207   0.275862068965517]

I try to do something like

set(get(h,'children'),'cdata', A );
colormap(colorset); 

but no luck

I think this should help:

   for hi = 1:numel(h)
        set(h(hi), 'FaceColor', colorset(hi,:))
   end

Before (orginal colors):

在此处输入图片说明

After (new colors): 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM