필터 지우기
필터 지우기

Bar chart is not plotted evenly over the X-axis!

조회 수: 2 (최근 30일)
Antonio
Antonio 2017년 4월 10일
댓글: Antonio 2017년 4월 11일
Could anybody tell me why my chart is not evenly plotted?! The space on the right side is bigger than the space on the left side when I run this code:
figure('name','Bar Chart','numbertitle','off');
Zone = {'Z1','Z2','Z3','Z4','Z5','Z6','Z7','Z8','Z9','Z10','Z11','ES', ...
'MS', 'HS', 'Hospital', 'Fire Station'};
Damage_Pct = [22 33 15 30; 30 15 20 35; 25 20 10 45; 20 10 5 65; 22 33 15 30; ...
30 15 20 35; 25 20 10 45; 20 10 5 65; 22 33 15 30; 30 15 20 35; ...
25 20 10 45; 20 10 5 65; 25 20 10 45; 20 10 5 65; 22 33 15 30; 30 15 20 35];
bar(Damage_Pct, 'stacked');
set(gca,'XTick',1:size(Zone,2),'XTickLabel',Zone);
title('Percentage of Damage in Different Zones');
xlabel('Zone');
ylabel('Percentage of Damage');
legend('DS1','DS2','DS3','DS4');
Thanks

채택된 답변

Rik
Rik 2017년 4월 11일
I don't know why, but you can easily fix this with the axis command, or on newer releases with the xlim command.
try
xlim([0 length(Zone)+1])
catch
axis([0 length(Zone)+1 0 100])
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by