Plotting different colors of Bar graph (2016a)

2 次查看(过去 30 天)
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.

采纳的回答

Adam Danz
Adam Danz 2019-6-24
编辑:Adam Danz 2019-6-28
" 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 个评论
Ali Tawfik
Ali Tawfik 2019-6-28
Thanks Adam,
it's working fine, I just added a new question, hope you could help me
thanks again :)
Adam Danz
Adam Danz 2019-6-28
Glad I could help. Your new question is answered, too.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by