Asked by Abdurrehman
on 24 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.

Answer by dpb
on 24 Feb 2017

dpb
on 25 Feb 2017

If you're really just drawing one bar, width is based on the percentage of the whole axis; in normal use for bar there are multiple bars and so the percentage is of the fraction 1/(N+1) of the axis width for each of the N bars (the axes xlim values are +/-0.5 past the 1:N values by default).

I can't imagine using 1E-14 as width, I'd think that would end up with nothing---oh, I see, anything <1E-5 or so appears as just a single pixel line. If that's the effect wanted, then just use line instead of bar.

But you're really trying to just draw a single bar of a specific dimension, probably using patch directly with a set of specific coordinates is the better choice.

Not sure what the end result desired is...

Muhammad Abdurrehman
on 25 Feb 2017

dpb
on 25 Feb 2017

As said, for the latter case, either:

- Heuristically uncover the width value that creates the size bar desired and use the resulting magic number, or
- 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.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.