Grouped Bar Series Xdata in 2014b

2 views (last 30 days)
Henry
Henry on 15 Jan 2015
Edited: z8080 on 9 Mar 2017
In Matlab versions prior to 2014b we could get the x-position of individual bars in a bar series like this:
hBar = bar(data);
x = get(get(hBar,'children'),'xdata');
With R2014b this does not work anymore. This breaks a lot of my existing code, thanks Mathworks! Is there a way to get the x-position of individual bars in a bar series in version 2014b?

Accepted Answer

Kelly Kearney
Kelly Kearney on 15 Jan 2015
You can get the position of the centers of each bar through the XOffset property:
hBar = bar(rand(10,5));
xb = bsxfun(@plus, hBar(1).XData, [hBar.XOffset]');
  5 Comments
Henry
Henry on 16 Jan 2015
Thank you, Kelly! Very helpful indeed.
z8080
z8080 on 9 Mar 2017
Edited: z8080 on 9 Mar 2017
Is there a way to also control this horizontal displacement/offset/jitter for an existing bar graph, i.e. not just find out how much it is? It appears to not be possible to directly assign a value to hBar.XOffset!

Sign in to comment.

More Answers (1)

Star Strider
Star Strider on 15 Jan 2015
Edited: Star Strider on 15 Jan 2015
That’s no longer possible. I submitted a Support Request complaining about the useful features in R2014a and earlier that were lost in HG2. Complain directly, and maybe MATLAB graphics will be useful again some day. I doubt there will be any immediate miracles, though.
Meanwhile, don’t uninstall R2014a ! (I haven’t.) You can have R2014a and R2014b open at the same time if you need to do something in R2014b that isn’t in R2014a, then pass the result to R2014a as a .mat file to do useful graphics.
EDIT —
Tell them to add the information in Kelly’s Answer in the ‘official’ documentation. She must have gotten in from the ‘Undocumented MATLAB’ site.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!