Stuart’s MATLAB Videos

Watch and Learn

Using HIST and BAR to customize your histograms 14

Posted by Doug Hull,

I recently had a question come in via e-mail where this MATLAB user wanted to be able to change the look of her histogram. The key to this problem was using HIST to generate the binning data and then use the more flexible BAR to make the bar chart look exactly as she wished. If HIST is used without a left hand side argument, then the function will make a plot using some default choices. If you want more control over the graph, you will have to use the flexibility of BAR to do that.

14 CommentsOldest to Newest

Marco replied on : 1 of 14
Hi doug, can I ask you a question about the histogram of an image? Here the simple code: N=200; A=randn(N,N); imshow(A), figure, imhist(A), axis tight The histogram does not look right. I am expecting a Gaussian looking centered at zero... thanks a lot, Marco
Steve Eddins replied on : 2 of 14
Marco—imhist assumes a dynamic range of [0,1] when you pass it a floating-point image, so it uses bins in that range.
Shalini replied on : 3 of 14
Can I have some tips on how to write a MATLAB code to plot a histogram without using the function "hist" Thanks, Shalini
dhull replied on : 4 of 14
@Shalini, Why would you want to? You can use the output from hist as input to BAR.m if you want finer control.
Chitra replied on : 7 of 14
Is it possible to put error bars for a histogram. the error bar will be the standard deviation of the values used to plot the histogram. Chitra
dhull replied on : 8 of 14
Never tried this, but it might work:
maria replied on : 9 of 14
Hi Doug, i want to ask you a question. I want a function which creates a histogram where the x axis will consist words and y axis numbers. For example, i have the names {'Paul' 'Kate' 'John' 'Alex'} and their ages {23 40 16 32} in a cell array 4x2. I want the names at x axis and ages at y axis. Is there any function to do this? Thanks a lot..
winnie replied on : 11 of 14
Hi Doug i would like to use hist command to help to plot a frequency table with class size of 5, is it possible? eg: input=1 2 3 7 8 9 table= [ 1-5 3 ; 6-10 3 ] thx a lot =)
dhull replied on : 12 of 14
@Winnie, You will want to choose the bins specifically as shown in the documentation for HIST.
Stuart McGarrity replied on : 14 of 14
imhist generates histograms of 2D image data (by binning and plotting), whereas hist does it for 1D column data. Bar perfoms just the plotting operation, taking the already calculated frequency data as input. See: