Adjusting bar colours in plot

조회 수: 19 (최근 30일)
Robin Vervaat
Robin Vervaat 2018년 3월 9일
편집: Adam 2018년 3월 9일
I am working with a bar chart that has at most 13 sub-bars per x-tick (see figure). The problem I have is that some bars appear as the same colour and I thus have no way to distinguish between them. (there are thirteen data sets I am trying to visualize, each of which can (partially)fall into 8 different categories)
I am trying to map a different set of colours to each individual bars by means of a unique RGB code. For the thirteen data entries I have here, I also have 13 unique RGB handles.
However I am unable to map the entries into the CData of the current figure, nor specify a different CData beforehand.
Below you can see the CData of the current figure:
if true
% code
%p1.CData
%ans =
%
% 0 0.4470 0.7410
% 0 0.4470 0.7410
% 0 0.4470 0.7410
% 0 0.4470 0.7410
% 0 0.4470 0.7410
% 0 0.4470 0.7410
% 0 0.4470 0.7410
% 0 0.4470 0.7410
%
%
%ans =
%
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980
% 0.8500 0.3250 0.0980%
%
%
%ans =
%
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
% 0.9290 0.6940 0.1250
%
%
%ans =
%
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
% 0.4940 0.1840 0.5560
end
where there are 13 of these 8 by 3 matrices(?)
I only want to ensure these bars all have a unique colour
  댓글 수: 1
Robin Vervaat
Robin Vervaat 2018년 3월 9일
Solved the problem I was having
if true
%
for i= 1:13
set(p1(:,i),'Facecolor',c(i,:))
set(p2(:,i),'Facecolor',c(i,:))
set(p3(:,i),'Facecolor',c(i,:))
set(p4(:,i),'Facecolor',c(i,:))
end
Where c is the list of 13 rows with a unique RGB code and p1,p2 etc the plot names.

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

답변 (1개)

Adam
Adam 2018년 3월 9일
편집: Adam 2018년 3월 9일
Try editing the 'ColorOrder' property of your axes to define 13 colours rather than the default 7 before you do the plotting. How you determine those colours is up to you, but those are what is used for plots (and I guess for bar charts too though I rarely use bar charts).
If there are fewer colours in 'ColorOrder' than there are plot objects it just cycles round those colours endlessly.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by