|
18 | 18 | import numpy as np
|
19 | 19 |
|
20 | 20 |
|
21 |
| -def adjacent_values(vals): |
22 |
| - q1, q3 = np.percentile(vals, [25, 75]) |
23 |
| - inter_quartile_range = q3 - q1 |
24 |
| - |
25 |
| - upper_adjacent_value = q3 + inter_quartile_range * 1.5 |
| 21 | +def adjacent_values(vals, q1, q3): |
| 22 | + upper_adjacent_value = q3 + (q3 - q1) * 1.5 |
26 | 23 | upper_adjacent_value = np.clip(upper_adjacent_value, q3, vals[-1])
|
27 | 24 |
|
28 |
| - lower_adjacent_value = q1 - inter_quartile_range * 1.5 |
| 25 | + lower_adjacent_value = q1 - (q3 - q1) * 1.5 |
29 | 26 | lower_adjacent_value = np.clip(lower_adjacent_value, vals[0], q1)
|
30 | 27 | return [lower_adjacent_value, upper_adjacent_value]
|
31 | 28 |
|
@@ -62,10 +59,11 @@ def set_axis_style(ax, labels):
|
62 | 59 | pc.set_edgecolor('black')
|
63 | 60 | pc.set_alpha(1)
|
64 | 61 |
|
65 |
| -quartiles = (np.percentile(data, [25, 50, 75], axis=1)) |
66 |
| -medians = quartiles[1] |
67 |
| -inter_quartile_ranges = quartiles[[0, 2]].T |
68 |
| -whiskers = [adjacent_values(sorted_array) for sorted_array in data] |
| 62 | +quartile1, medians, quartile3 = np.percentile(data, [25, 50, 75], axis=1) |
| 63 | +inter_quartile_ranges = np.vstack([quartile1, quartile3]).T |
| 64 | +whiskers = [ |
| 65 | + adjacent_values(sorted_array, q1, q3) |
| 66 | + for sorted_array, q1, q3 in zip(data, quartile1, quartile3)] |
69 | 67 |
|
70 | 68 | # plot whiskers as thin lines, quartiles as fat lines,
|
71 | 69 | # and medians as points
|
|
0 commit comments