フィルターのクリア

How to optimise bar chart display?

1 回表示 (過去 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 Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by