How can I make my histogram bin edges the bin centers instead?
89 views (last 30 days)
Show older comments
MathWorks Support Team
on 22 Mar 2016
Answered: MathWorks Support Team
on 14 Apr 2016
How can a histogram plot be modified, independent of the data, so as to make its bin centers its old bin edges?
Accepted Answer
MathWorks Support Team
on 22 Mar 2016
The below steps apply from MATLAB R2014b or newer. For older versions, use the appropriate "set" and "get" functions for graphics.
1) Obtain a handle to the histogram when first plotting it:
histHandle = histogram(data);
If the histogram has already been plotted in 'Figure n', obtain it in the following manner:
figHandle = figure(n);
axisHandle = figHandle.Children;
histHandle = axisHandle.Children;
2) Offset the bin edges by half the bin width:
histHandle.BinEdges = histHandle.BinEdges + histHandle.BinWidth/2;
Be careful not to eliminate a half-bin with data when doing this. If required, add an extra bin edge to the beginning of the "histHandle.BinEdges" vector.
0 Comments
More Answers (0)
See Also
Categories
Find more on Histograms 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!