MATLAB Answers

How to change boxplot filling with newer Matlab versions?

조회 수: 3(최근 30일)
Max Behr
Max Behr 18 Jun 2020
댓글: dpb 18 Jun 2020
Hello,
I would like to change the filling of the boxplots
boxplot(y,'Labels',{'1','2','3'},'Color','k')
xlabel('X')
ylabel('Y')
title('XY')
Now I would like to fill each boxplot with a color like black, gray and dark grey.
So:
First Boxplot => black
Second BP=> gray
Third BP=> dark gray
Unfortunately the 'children' code won't work anymore.
Can you help me?
Thanks.

  댓글 수: 3

dpb
dpb 18 Jun 2020
Just use the 'Colors' named option with an rgb array...
Max Behr
Max Behr 18 Jun 2020
I did it like this:
h = findobj(gca,'tag','Box');
This selects only the box color :)
dpb
dpb 18 Jun 2020
+1
The implementation leaves much to be desired...I had presumed the colors with the 'filled' option would work as one would expect -- who woulda' thunk they'd have broken it such that if use that, then can only get the narrow little boxes; the 'traditional' style and 'width' parameters are ignored.
Worth a bug/quality of implementation report.
Why it doesn't return a handle to the object also breaks any symmetry with other plotting routines -- TMW continues with the trend to less and less coherence in user interface design and implementation...making things act so differently from one to another so lessons learned aren't... :(

댓글을 달려면 로그인하십시오.

답변(1개)

Mara
Mara 18 Jun 2020
You can specify an array for the color, it should have the same size as the columns in y.
boxplot (y, 'Colors', ['k' 'r' 'b'], 'BoxStyle', 'filled');
or for your colors in rgb triplets:
boxplot (y, 'Colors', [0,0,0; 0.5 0.5 0.5; 0.3 0.3 0.3], 'BoxStyle', 'filled');

  댓글 수: 0

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by