필터 지우기
필터 지우기

How can I change the color of specific boxcharts?

조회 수: 67 (최근 30일)
Rafael Cordero
Rafael Cordero 2021년 12월 2일
댓글: Adam Danz 2021년 12월 2일
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!

답변 (1개)

Adam Danz
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.
Alternatively, you could plot each box individually in a loop. That is demonstrated in this answer.
  댓글 수: 2
Rafael Cordero
Rafael Cordero 2021년 12월 2일
Woops, I meant to say b = boxchart(...), not subplot(...) = boxchart
Adam Danz
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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by