Plotting different colors of Bar graph (2016a)

4 views (last 30 days)
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.

Accepted Answer

Adam Danz
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'})
  2 Comments
Ali Tawfik
Ali Tawfik on 28 Jun 2019
Thanks Adam,
it's working fine, I just added a new question, hope you could help me
thanks again :)
Adam Danz
Adam Danz on 28 Jun 2019
Glad I could help. Your new question is answered, too.

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Data 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!