Adjusting histogram bin width.
105 次查看(过去 30 天)
显示 更早的评论
I have a histogram with a large range of data. It can run up to figures of 10^135(not many), these figures however are largely irrelevant as everything interesting is happening at very close to zero(most figures are close to zero). I need to somehow fit about 20-30 bins between the range of -0.3 and 0.3 to see what is happening, but the bin widths that matlab has is too large as it just puts everything close to zero in one single bar and that's no use to me.
How do I adjust the bin widths? I tried increasing the number of bins but that doesn't seem to help, I still get one giant spike near zero and this needs to be split up to more bins.
0 个评论
回答(2 个)
Josh Meyer
2015-3-27
If you use the new histogram function, introduced in R2014b, there is a great deal of control for problems like this.
To plot a histogram with 30 bins between -0.3 and 0.3, try this:
x = randn(1000,1);
h = histogram(x,30,'BinLimits',[-0.3 0.3])
Note that when you specify the BinLimits, histogram only plots the data that falls within those limits inclusively.
To plot all of the data but still improve the resolution between -0.3 and 0.3, you can just explicitly specify all of the bin edges with a vector as the second input, perhaps something like this:
edges = [-5:0.5:-0.5, linspace(-0.5,0.5,30), 0.5:0.5:5];
h = histogram(x,edges)
More information:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!