Make a histogram Arguments: height -- the height of the histogram in # of lines bincount -- number of bins in the histogram binwidth -- width of bins in the histogram pch -- shape of the bars in the plot colour -- colour of the bars in the terminal
(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="default", title="", xlab=None, showSummary=False, regular=False)
| 89 | |
| 90 | |
| 91 | def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="default", title="", xlab=None, showSummary=False, regular=False): |
| 92 | """ |
| 93 | Make a histogram |
| 94 | |
| 95 | Arguments: |
| 96 | height -- the height of the histogram in # of lines |
| 97 | bincount -- number of bins in the histogram |
| 98 | binwidth -- width of bins in the histogram |
| 99 | pch -- shape of the bars in the plot |
| 100 | colour -- colour of the bars in the terminal |
| 101 | title -- title at the top of the plot |
| 102 | xlab -- boolean value for whether or not to display x-axis labels |
| 103 | showSummary -- boolean value for whether or not to display a summary |
| 104 | regular -- boolean value for whether or not to start y-labels at 0 |
| 105 | """ |
| 106 | if pch is None: |
| 107 | pch = "o" |
| 108 | |
| 109 | if isinstance(f, str): |
| 110 | with open(f) as fh: |
| 111 | f = fh.readlines() |
| 112 | |
| 113 | min_val, max_val = None, None |
| 114 | n, mean, sd = 0.0, 0.0, 0.0 |
| 115 | |
| 116 | for number in read_numbers(f): |
| 117 | n += 1 |
| 118 | if min_val is None or number < min_val: |
| 119 | min_val = number |
| 120 | if max_val is None or number > max_val: |
| 121 | max_val = number |
| 122 | mean += number |
| 123 | |
| 124 | mean /= n |
| 125 | |
| 126 | for number in read_numbers(f): |
| 127 | sd += (mean - number)**2 |
| 128 | |
| 129 | sd /= (n - 1) |
| 130 | sd **= 0.5 |
| 131 | |
| 132 | bins = list(calc_bins(n, min_val, max_val, bincount, binwidth)) |
| 133 | hist = dict((i, 0) for i in range(len(bins))) |
| 134 | |
| 135 | for number in read_numbers(f): |
| 136 | for i, b in enumerate(bins): |
| 137 | if number <= b: |
| 138 | hist[i] += 1 |
| 139 | break |
| 140 | if number == max_val and max_val > bins[len(bins) - 1]: |
| 141 | hist[len(hist) - 1] += 1 |
| 142 | |
| 143 | min_y, max_y = min(hist.values()), max(hist.values()) |
| 144 | |
| 145 | start = max(min_y, 1) |
| 146 | stop = max_y + 1 |
| 147 | |
| 148 | if regular: |
no test coverage detected