# How to assign different colormaps to different stacked bars

2 views (last 30 days)
Tasi on 18 Nov 2017
Commented: Tasi on 18 Nov 2017
I have a defined variable of 2x12, and would like to create a stacked bar plot but using two different colormaps defined below:
c1=[0 0 1];%B
c2=[1 1 1];%W
c3=[1 0 0]; %R
n3=11;
n4=53;
cmap1=[linspace(c1(1),c2(1),n3);linspace(c1(2),c2(2),n3);linspace(c1(3),c2(3),n3)];
cmap1(:,end+1:end+n4)=[linspace(c2(1),c3(1),n4);linspace(c2(2),c3(2),n4);linspace(c2(3),c3(3),n4)];
n5=42;
n6=22;
cmap2=[linspace(c1(1),c2(1),n5);linspace(c1(2),c2(2),n5);linspace(c1(3),c2(3),n5)];
cmap2(:,end+1:end+n6)=[linspace(c2(1),c3(1),n6);linspace(c2(2),c3(2),n6);linspace(c2(3),c3(3),n6)];
I don't know how to apply these two different colormaps on the two stacked bar plots without one overwriting the other, so I always end up with the same colormap for both stacks. Any suggestions?
Thanks!

Walter Roberson on 18 Nov 2017
Draw the first item and apply its colormap. Use freezeColors() to convert it to RGB from pseudocolor. Now you can draw the second item and apply its colormap because the first item is no longer using colormaps.
Tasi on 18 Nov 2017
I am trying to adjust this code, but it is still not doing it. I am trying to figure out why that is. Thanks so much for your help.