Adjusting bar colours in plot

18 vues (au cours des 30 derniers jours)
Robin Vervaat
Robin Vervaat le 9 Mar 2018
Modifié(e) : Adam le 9 Mar 2018
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 commentaire
Robin Vervaat
Robin Vervaat le 9 Mar 2018
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.

Connectez-vous pour commenter.

Réponses (1)

Adam
Adam le 9 Mar 2018
Modifié(e) : Adam le 9 Mar 2018
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.

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by