필터 지우기
필터 지우기

How to optimise bar chart display?

조회 수: 2 (최근 30일)
Benedict Low
Benedict Low 2017년 5월 13일
댓글: dpb 2017년 5월 13일
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!

채택된 답변

dpb
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
Benedict Low
Benedict Low 2017년 5월 13일
It worked!
Just two points - it is better to start from zero, and the order of your closing bracket and parenthesis need to be swapped!
xlim([0 size(sample,1)+1])
Many thanks!
dpb
dpb 2017년 5월 13일
Yeah, my typing is getting atrocious--and the '1' was certainly intended as 0. I'll fixup answer...

댓글을 달려면 로그인하십시오.

추가 답변 (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