Width of bar in bar plotting is very high

6 views (last 30 days)
Abdurrehman
Abdurrehman on 24 Feb 2017
Edited: dpb on 26 Feb 2017
I am using following piece of code in my GUI to plot a bar in an axes, it works very fine when I run GUI in Matlab but when I run this after making its Installer (using Matlab Compiler) the width of bar appears very high. It covers almost 85% of the axes
y=[3.02];
x=[1];
color=[0 0.25 .5];
bar(1,y(1),0.1,'parent',h,'FaceColor',color);
hold on;
h.Color=[ 0.945 0.969 0.949];
h.FontSize=12;
h.FontWeight='bold';
Please let me know how to resolve this issue.

Answers (1)

dpb
dpb on 24 Feb 2017
I'd guess using the 'BarWidth' property will help--it's 0.8 by default, decrease that value for narrower bar widths.
  4 Comments
Muhammad Abdurrehman
Muhammad Abdurrehman on 25 Feb 2017
Actually in my application user can compare/plot 1 to maximum 4 different systems testing results. So there are 4 different bar plots on said axes when 4 system names are entered. The bar width is excellent if user intends to compare/plot 2 to 4 systems. but if only one system name is entered. So in this case the width of bar is expended over 90% of the axes.
dpb
dpb on 25 Feb 2017
Edited: dpb on 26 Feb 2017
As said, for the latter case, either:
  1. Heuristically uncover the width value that creates the size bar desired and use the resulting magic number, or
  2. Compute the size/locations and make a patch object directly
seems to me the basic workarounds available.
Oh, I guess a third would be to delve into the guts of bar.m and see if can divine the algorithm used and either patch it or make a copy by another name and fix it to work as desired.
ADDENDUM
Note that if use width,1 that the bar indeed covers the entire axis and that xlim returns [0.5 1.5]. From this, one could compute the value that covers whatever range of the x-axes you desire the bar to span to compute the width factor.
Unfortunately, with HG2, TMW has made a difficult-to-work-with object (the bar plot) even more so--in fact some things have become essentially impossible. Before the new bar series object, one could retrieve the coordinates of the underlying patch objects from which could compute things like midpoints for bar labels, etc. Here that would let you determine the actual physical x location from the result rather than trying to compute it. It seems that
0.8=dx/1 --> dx=0.8 so 1-0.8/2=0.6
will be the LH bar location by default. If you can define the position you think is the right x-position to get the aspect ratio you like, then you can use the above to compute the width parameter that will create that bar width.

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!