how to set xrange of a bar plot?

4 views (last 30 days)
Mr M.
Mr M. on 31 Mar 2015
Commented: dpb on 31 Mar 2015
I have vector data (v) with length 20, but bar(v) displays a plot with range 1-25 which is very ugly! Why? And how to solve this problem?

Answers (1)

dpb
dpb on 31 Mar 2015
xlim([0 21])
set(gca,'xtick',[1 5:5:20])
I often will set the xlim values to some fractional value other than [0 N+1] as above to make the whitespace closely approximate that between the bars but it's a matter of taste. I didn't try to put all the tick mark values in as they get a little cluttered sometimes; again "salt to suit"...
  1 Comment
dpb
dpb on 31 Mar 2015
You would think bar and friends could be a lot smarter about scaling the x-axis automagically than they are, though, agreed. Perhaps you could couch this as an enhancement suggestion and submit it at the "official" TMW site at www.mathworks.com

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!