Help With Bar Position
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello!!
I would like to create a bar graph that has four bars. The first three show data, the last is a percent increase of one variable over one of the other data bars. I would like the fourth bar to be further away from the other three. Please help!!
%Data
Data=[8 12]
%Percent Increase
PI=[50]
Names={'Before','After','%Change'}
figure name (One Vs The Other);
bar(1,Data(1),'FaceColor','g');
ylim([0,100]);
hold on
bar(2,Data(2),'FaceColor','b');
%I want the following bar to be spaced further out from the first two...)
bar(3,PI,'FaceColor','r');
labels=(Names);
set(gca,'XTick',[1 2 3]);
set(gca,'XTickLabel',labels);
xlabel('Condition');
ylabel('Sales');
title('Sales Before and After Advertising');
box off
yyaxis right
ylabel('Percent Increase');
댓글 수: 0
답변 (1개)
Luna
2018년 11월 20일
Hi Naomi,
You can add zero value bars to add it to further I think.
Try that below:
%Data
Data=[8 12]
%Percent Increase
PI=[50]
Names={'Before','After','%Change', '','', 'other'}
figure name (One Vs The Other);
bar(1,Data(1),'FaceColor','g');
ylim([0,100]);
hold on
bar(2,Data(2),'FaceColor','b');
%I want the following bar to be spaced further out from the first two...)
bar(3,PI,'FaceColor','r');
bar(4,0);
bar(5,0);
bar(6,1,'FaceColor','m');
labels=(Names);
set(gca,'XTick',[1 2 3 4 5 6]);
set(gca,'XTickLabel',labels);
xlabel('Condition');
ylabel('Sales');
title('Sales Before and After Advertising');
box off
yyaxis right
ylabel('Percent Increase');
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!