Colored error bar plot with X axis labels
Show older comments
Hi Everyone, I am trying to create a bar graph with individually colored bars and also with error bars. However I cannot seem to get X axis labels under each bar. I have tried various suggestions from the Answers and File Exchange, but for some reason it's not working for me. Here are two scripts that I have tried (version 2016a):
% first try
X=[1 2 0.25; 2 3 0.55];
figure
bar(X(1,1),X(1,2),0.5,'FaceColor','b');
hold on
bar(X(2,1),X(2,2),0.5,'FaceColor','r');
hold on
errorbar(X(1:2,2),X(1:2,3),'LineStyle','none','Color','k');
set(gca,'XTickLabel',{'Light','Dark'});
X=[1 2 0.25; 2 3 0.55];
% Second try
figure
bar(X(1,1),X(1,2),0.5,'FaceColor','b');
hold on
bar(X(2,1),X(2,2),0.5,'FaceColor','r');
hold on
errorbar(X(1,1),X(1,2),X(1,3),'LineStyle','none','Color','k');
set(gca,'XTickLabel','Light');
hold on
errorbar(X(2,1),X(2,2),X(2,3),'LineStyle','none','Color','k');
set(gca,'XTickLabel','Dark');
hold on
Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!