Borrar filtros
Borrar filtros

Grouped Bar plot- colors for groups

5 visualizaciones (últimos 30 días)
Simon
Simon el 8 de Jul. de 2014
Respondida: Aurele Turnes el 4 de Ag. de 2014
Dear all,
I have following plot:
ba=([P1,P2); %P_n is n x 1
bar(ba,'grouped');
now I want to seperately color the first and the second bar of each group with different colors. And each group gets a different set of colors, so that I have to use 2*n colors in total, which I have defined via RGB values beforehand.
How do I do this? I tried to work with set() and FaceColor, but it turned everything the same.
Thanks!

Respuestas (1)

Aurele Turnes
Aurele Turnes el 4 de Ag. de 2014
If you are using MATLAB R2014a or earlier versions, you can recolor individual bars by first getting a handles to the bar plot as follows:
bar_handle = bar(ba,'grouped');
Then, access the groups by accessing the children of the handle above:
bar_group = get(bar_handle,'children');
Now, you can decide what colors you want each individual bar to have by giving them a color index and setting the 'FaceVertexCData' property for that group. For instance, if there are n bars in the first group, and you want the first bar to be a different color, you can do:
fvcd = ones(n,1);
fvcd(1) = 3;
set(bar_group{1},'FaceVertexCData',fvcd)
This is not supported in the MATLAB R2014b_Prerelease however.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by