Calculate number of bins for the histogram
(n, min_val, max_val, h=None, binwidth=None)
| 18 | |
| 19 | |
| 20 | def calc_bins(n, min_val, max_val, h=None, binwidth=None): |
| 21 | """ |
| 22 | Calculate number of bins for the histogram |
| 23 | """ |
| 24 | if not h: |
| 25 | h = max(10, math.log(n + 1, 2)) |
| 26 | if binwidth == 0: |
| 27 | binwidth = 0.1 |
| 28 | if binwidth is None: |
| 29 | binwidth = (max_val - min_val) / h |
| 30 | for b in drange(min_val, max_val, step=binwidth, include_stop=True): |
| 31 | if b.is_integer(): |
| 32 | yield int(b) |
| 33 | else: |
| 34 | yield b |
| 35 | |
| 36 | |
| 37 | def read_numbers(numbers): |