MCPcopy Index your code
hub / github.com/plotly/plotly.py / calc_stats

Function calc_stats

plotly/figure_factory/_violin.py:13–38  ·  view source on GitHub ↗

Calculate statistics for use in violin plot.

(data)

Source from the content-addressed store, hash-verified

11
12
13def calc_stats(data):
14 """
15 Calculate statistics for use in violin plot.
16 """
17 x = np.asarray(data, float)
18 vals_min = np.min(x)
19 vals_max = np.max(x)
20 q2 = np.percentile(x, 50, method="linear")
21 q1 = np.percentile(x, 25, method="lower")
22 q3 = np.percentile(x, 75, method="higher")
23 iqr = q3 - q1
24 whisker_dist = 1.5 * iqr
25
26 # in order to prevent drawing whiskers outside the interval
27 # of data one defines the whisker positions as:
28 d1 = np.min(x[x >= (q1 - whisker_dist)])
29 d2 = np.max(x[x <= (q3 + whisker_dist)])
30 return {
31 "min": vals_min,
32 "max": vals_max,
33 "q1": q1,
34 "q2": q2,
35 "q3": q3,
36 "d1": d1,
37 "d2": d2,
38 }
39
40
41def make_half_violin(x, y, fillcolor="#1f77b4", linecolor="rgb(0, 0, 0)"):

Callers 1

violinplotFunction · 0.85

Calls 1

minMethod · 0.45

Tested by

no test coverage detected