How can I change the color of specific boxcharts?
조회 수: 79 (최근 30일)
이전 댓글 표시
Hello all,
I'm having some problems coloring bar charts.
If I have a subplot which is a boxchart( ) with several little boxcharts that I want to be colored according to varialbe 'col' representing and RGB triplet:
subplot(3, 1, 2); b = boxchart(rand(100, 10), 'BoxFaceColor', col)
Let's say I want to change the color of SOME of these 10 boxcharts to black. The specific boxcharts to recolor could be given by a logical vector 'recolor'
recolor = logical([0 0 1 1 0 1 0 0 1 0]);
Where logical 1 would indicate that that particular subplot should be recolored to black.
How exactly can I perform this recoloring of specific boxcharts?
Thank you!
댓글 수: 0
답변 (1개)
Adam Danz
2021년 12월 2일
It looks like you're either using "subplot" as a variable name of erroneously assigning boxchart handles to the subplot function.
❌ subplot(3, 1, 2) = boxchart(rand(100, 10), 'BoxFaceColor', col)
One way to control boxchart color is by using groupByColor which is demonstrated in the documentation. That outputs a vector of handles, one for each group. You can change the color using the BoxFaceColor property of each handle but then entire subgroup will always have the same color. One way around that is to make each boxplot its own group.
댓글 수: 2
Adam Danz
2021년 12월 2일
Another alternative is to use boxplot instead of boxchart. You can edit the edge colors but boxplot does not have an option to fill the boxes.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!