Addded automatic bin selection in histogram plot
This commit is contained in:
parent
3f7215bc35
commit
72e300c95e
|
@ -575,7 +575,8 @@ class HistogramPlot(Plot):
|
||||||
|
|
||||||
# Set default paramteters
|
# Set default paramteters
|
||||||
if not kw.has_key('bins'):
|
if not kw.has_key('bins'):
|
||||||
kw['bins'] = 20
|
kw['bins'] = self._get_binsize()
|
||||||
|
print kw['bins']
|
||||||
|
|
||||||
# Initial draw
|
# Initial draw
|
||||||
self.axes.grid(False)
|
self.axes.grid(False)
|
||||||
|
@ -653,6 +654,16 @@ class HistogramPlot(Plot):
|
||||||
patch.set_facecolor((r,g,b,1))
|
patch.set_facecolor((r,g,b,1))
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
def _get_binsize(self, min_bins=2, max_bins=100):
|
||||||
|
""" Automatic bin selection, as described by Shimazaki."""
|
||||||
|
bin_vec = scipy.arange(min_bins, max_bins, 1)
|
||||||
|
D = self._data.ptp()/bin_vec
|
||||||
|
cost = scipy.empty((bin_vec.shape[0],), 'f')
|
||||||
|
for i, bins in enumerate(bin_vec):
|
||||||
|
count, lims = scipy.histogram(self._data, bins)
|
||||||
|
cost[i] = (2*count.mean() - count.var())/(D[i]**2)
|
||||||
|
best_bin_size = bin_vec[scipy.argmin(cost)]
|
||||||
|
return best_bin_size
|
||||||
|
|
||||||
class BarPlot(Plot):
|
class BarPlot(Plot):
|
||||||
"""Bar plot.
|
"""Bar plot.
|
||||||
|
|
Reference in New Issue