How to assign color for different column in a group wise bar chart?

I am creating a bar chart of 4 groups of data each containing 3 columns. I want to assign red for highest column and blue for smallest column in each group.
Here is my code.
exp1 = [1 2 3; 4 5 9; 8 1 6; 4 3 8];
figure()
h = bar(exp1);
set(gca,'XTickLabel',{'n-Heptane','O_2','CO','CO_2'});
for k = 1 :size(exp1,2)
h(k).CData = k;
end
And There is a common xTicklabel for each group. How can i name each column along with common group name?

4 comentarios

Adam
Adam el 14 de En. de 2019
Editada: Adam el 14 de En. de 2019
You can only assign one colour for the first column, one for the second, etc, you can't assign multiple different colours to the first column of different groups depending on if it is the biggest or not as far as I am aware.
You could sort your data in such a way that the first column is always the smallest and the final column always the largest though, then colour them appropriately.
You need to set
h.FaceColor = 'flat'
for your colours to show.
Mr. 206
Mr. 206 el 14 de En. de 2019
Editada: Mr. 206 el 14 de En. de 2019
I did this with single bar chart like,
A=[5.63785660873606e+00;
1.08781197953167e+01;
1.13383362441711e+01;
6.73837307756419e+00;
9.46017282747908e+00];
%subplot(6,4,1)
figure(1)
xticks = 1:numel(A);
set(gca,'XTick',xticks)
box on
hold on
for i = 1:length(A)
h=bar(i,A(i));
if A(i) == min(A)
set(h,'FaceColor','b');
elseif A(i) == max(A)
set(h,'FaceColor','r');
else
set(h,'FaceColor','k');
end
end
Yes, you can do it with a single bar chart. I even took the time to answer that very question on here last week, but you deleted the question before I posted my answer!
Can't it be extended for Groupwise bar chart?

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Preguntada:

el 14 de En. de 2019

Comentada:

el 14 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by