Plotting different colors of Bar graph (2016a)

조회 수: 12 (최근 30일)
Ali Tawfik
Ali Tawfik 2019년 6월 24일
댓글: Adam Danz 2019년 6월 28일
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에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by