Is it possible to extract bars from the hist or histogram function?
1 view (last 30 days)
Show older comments
I would like to extract the bar-rectangle coordinates (the shapes themself) from the histogram plot. Is it possible?
8 Comments
Walter Roberson
on 30 Sep 2015
data = [rand(1,50)];
xlim([0 2]);
ylim([0 100]);
h1 = hgtransform('Matrix',makehgtform('scale',0.5));
[n,x] = hist(data);
bar(x, n, 'Parent', h1);
drawnow;
The difficulty that you ran into is that when you specify output variables, hist() does not draw the histogram, and instead just returns the computed data. The newer histogram() function always draws the data and returns the handle.
Answers (2)
Walter Roberson
on 28 Sep 2015
If you are using hist() to do the plot, then it uses bar() to do the plots, and bar() creates a patch() object; see http://www.mathworks.com/help/matlab/ref/hist.html#btsgtr1-1_1 . You can examine the properties of the patch() object. It will not be the most fun you've had all day, but it can be done (I have done it.)
0 Comments
Thorsten
on 28 Sep 2015
The values you are looking for are returned by the histogram function:
h = hist(x);
plot(h)
4 Comments
See Also
Categories
Find more on Data Distribution Plots 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!