Is it possible to extract bars from the hist or histogram function?
Show older comments
I would like to extract the bar-rectangle coordinates (the shapes themself) from the histogram plot. Is it possible?
8 Comments
Steven Lord
on 28 Sep 2015
Why?
Mr M.
on 28 Sep 2015
Walter Roberson
on 28 Sep 2015
Is it possible that using a hgtransform() would work for your purpose? If you have a graphics object that does not allow you to directly position it in an axes, you can parent the graphics object to an hgtransform and use that to scale and translate it.
Steven Lord
on 29 Sep 2015
Can you show a picture of the type of "graphic matrix" you want? I'm not quite sure I understand what you're trying to do quite yet.
Mr M.
on 29 Sep 2015
Walter Roberson
on 29 Sep 2015
Mr M.
on 30 Sep 2015
Edited: Walter Roberson
on 30 Sep 2015
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
2 votes
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.)
Thorsten
on 28 Sep 2015
The values you are looking for are returned by the histogram function:
h = hist(x);
plot(h)
Categories
Find more on Object Containers 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!