Grouped Bar plot- colors for groups
9 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
Aurele Turnes
2014 年 8 月 4 日
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!