How to assign different colormaps to different stacked bars
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
Walter Roberson
2017-11-18
Look in the File Exchange for freezeColors().
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.
6 个评论
Walter Roberson
2017-11-18
b = bar(var1, 'stacked');
for K = 1 : length(b); b(K).FaceColor = cmap1(:,K).'; end
and likewise with the second variable.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!