Help With Bar Position

7 次查看(过去 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 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by