How to assign different colormaps to different stacked bars
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 18 de Nov. de 2017
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 comentarios
Walter Roberson
el 18 de Nov. de 2017
b = bar(var1, 'stacked');
for K = 1 : length(b); b(K).FaceColor = cmap1(:,K).'; end
and likewise with the second variable.
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!