![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226277/image.jpeg)
Plotting different colors of Bar graph (2016a)
9 views (last 30 days)
Show older comments
Hi All,
I have been trying to plot bar with different colors, I'd also like to plot yaxis with numbers, and add names in the x-axis. I als seacrhed a lot in the internet, but someimtes, they use another version, or make it really complicated.
figure1=figure
y2=[64.5, 54.6, 44.7, 24.8, 52.2, 6.6, 3.2, 5.2, 52.4, 5.1]
bar(y2)
%set(y2(1),'FaceColor','r');
%set(y2(2),'FaceColor','b')
legend('fb','tw','gplus','linked','insta','p','wordplus','flick','youtube','nouse')
%x_axisname={'fb','tw','gplus','linked','insta','p','wordplus','flick','youtube','nouse'};
%set(gca,'xticklabel',x_axisname)
Looking to hearing your help guys.
0 Comments
Accepted Answer
Adam Danz
on 24 Jun 2019
Edited: Adam Danz
on 28 Jun 2019
" I have been trying to plot bar with different colors"
For newer releases, this is fairly straightforward (demo) but for r2016a you can make a diagonal matrix with a stacked bar chart so that every bar is editable.
figure();
y2 = [64.5, 54.6, 44.7, 24.8, 52.2, 6.6, 3.2, 5.2, 52.4, 5.1];
bh = bar(1:numel(y2),diag(y2),'stacked','FaceColor', 'c'); %specify default color
% Set specific colors
bh(1).FaceColor = 'r'; %bar 1
bh(2).FaceColor = 'b'; %bar 2....
"I'd also like to plot yaxis with numbers and add names in the x-axis"
Not sure what you mean here. Numbers are already present on the y axis by default. To add names in the x axis,
set(gca,'XTick', 1:numel(y2),'XTickLabel',{'one','two','three','pi','four','five','foo','bar','ali','done'})
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226277/image.jpeg)
2 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!