How to optimise bar chart display?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I created a stacked bar chart from a 20 by 6 matrix. The code looks like this
sample=randi([0,10],20,6);
figure; bar(sample, 'stacked');
And this gives me the following

My problem is that there is a lot of white space from the last bar to the end of the diagram, and this makes the bars more "cramped" than they need to be. And because I need to insert xticklabels later on, it will be really helpful if the diagram can be optimised to "fit the screen". Is there any way to do that?
I ask this because normally, Matlab naturally optimises the space, such as in this 11 by 6 matrix, where there is no wasted space.

Any help is appreciated. Thank you!
댓글 수: 0
채택된 답변
dpb
2017년 5월 13일
편집: dpb
2017년 5월 13일
Hmmm....that is a failure in the internal scaling algorithm fur shure...easy enough to fix, though; bar axis center values for default are just 1:N
xlim([0 size(sample,1))+1]
to set RH limit at the last bar+1 as is LH.
The default is [0 25] so the logic internally is more concerned about rounding and even numbers even for the bar plot than it is about spacing/appearance. This is on the nuisance end, but even this is worthy of an enhancement request imo as it isn't what should have to deal with; graphics should "just work" and look good.
댓글 수: 2
dpb
2017년 5월 13일
Yeah, my typing is getting atrocious--and the '1' was certainly intended as 0. I'll fixup answer...
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!