![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226277/image.jpeg)
Plotting different colors of Bar graph (2016a)
조회 수: 9 (최근 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.
댓글 수: 0
채택된 답변
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'})
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226277/image.jpeg)
댓글 수: 2
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!