Help With Bar Position

조회 수: 8 (최근 30일)
Naomi Bean
Naomi Bean 2018년 11월 20일
답변: Luna 2018년 11월 20일
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');

답변 (1개)

Luna
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');

카테고리

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