Bar plot with bars in different colors
Show older comments
Hi I have the common problem. I have to plot a bar chart with sorted medians for enzymes and the enzymes shall be colored in blue or red depending on their reversibility.
Here is the data:
data = [.142 31 1;.156 7 1;.191 2 0;.251 6 0]
%First column is the sorted value
%Second column is the index for the YTickLabel
%Third column is the reaction direction
% Data(1,3) = 1 -> bar in red
% Data(1,3) = 0 -> bar in blue
uniNames = {'eno','pck','zwf','...'};
%This was the original script....
h = hist(data(1:end,1))
xlabetxt = uniNames(data(:,2));
ylim([0 .5])
text(1:length(xlabetxt),repmat(-max(ylim)/50,length(xlabetxt),1),xlabetxt','horizontalalignment','right','Rotation',90,'FontSize',15)
text
text(.55,77.5,'A','FontSize',15)
ylabel('median log2 fold change','FontSize',15)
Accepted Answer
More Answers (5)
Hello kity
on 18 Jan 2013
Edited: Hello kity
on 18 Jan 2013
you can also manually select bar and color:
bar(1, Data, 'colorcode')
hold on
bar(2, Data, 'colorcode') , bar (3, Data, 'colorcode')
that is what Thorsten does here:
h = bar(i, H(i));
1 Comment
Iyk
on 17 Apr 2013
AWESOME!!!!!!!!1
Dr. Murtaza Ali Khan
on 16 Mar 2019
Edited: Dr. Murtaza Ali Khan
on 16 Mar 2019
1 vote
mydata=rand(1,10)
color= ['r','g','b','k'];
figure, hold on
% % if data is more than colors then colors will be repeated
m = length(color);
for k = 1:length(mydata)
i = mod(k-1,m); %%i is remainder after division of k-1 by m
i = i+1;
h=bar(k,mydata(k));
set(h,'FaceColor',color(i));
end
SUDHEEP
on 30 Oct 2013
0 votes
try this > a=2; >> b=4; >> bar(a) >> hold on >> bar(2,b,'r') >> axis([0 5 0 6])
Categories
Find more on Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!