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!