Multiple histogram with different colors for each bar

조회 수: 3 (최근 30일)
Marco Magli
Marco Magli 2019년 6월 12일
댓글: Marco Magli 2019년 6월 13일
Hi to everybody,
I plotted an histogram of different set of data in different columns with the command bar:
bar((linspace(1,nx,nx))',matY');
where nx is the number of column of matY. Furthermore, the histogram for every point in x has m different columns as the number of rows of matY. The resultant plot is:
histogram.png
Now, I would like to change the colors of the columns, so every type of rho has the color that I want. How can I do?
Thank you

채택된 답변

Adam Danz
Adam Danz 2019년 6월 12일
편집: Adam Danz 2019년 6월 12일
Use the output handles to the bar objects.
h = bar(1:nx,matY');
h(1).FaceColor = [0 0 0]; %first bar group
h(2).FaceColor = 'g'; %second bar group
% Etc...
Or set all colors at once.
c = [1 0 0 %one [r,g,b] color vector per bar group
0 1 0
0 0 1
1 1 0
0 1 1];
set(h, {'FaceColor'}, mat2cell(c,ones(size(c,1),1),3))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by