1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Data = [] for i in range(4): mean = np.random.uniform(0.3,0.5) std = np.random.uniform(0.2,0.3) lent = int(10000*np.random.rand()) data = np.random.normal(mean, std, lent)
dmin = np.random.uniform(0.0, 0.15) dmax = np.random.uniform(0.5, 0.75) data = data[data>dmin] data = data[data<dmax]
print(mean, std, data.shape) print(data.mean(), data.std())
Data.append(data)
fig, ax = plt.subplots()
for i, data in enumerate(Data): ax.boxplot(data, positions=[i], widths=0.3, showfliers=False, medianprops={'color': f'C{i}', 'linewidth': 2}, whiskerprops={'color': f'C{i}', 'linewidth': 2}, capprops={'color': f'C{i}', 'linewidth': 2}, boxprops={'color': f'C{i}', 'linewidth': 2})
x = [(0,3),(0,2),(1,3),(1,2),(2,3)] print(len(x)) y = np.linspace(0.98, 0.75, len(x))
for i in range(len(x)): x1, x2 = x[i] ax.plot([x1, x2], [y[i], y[i]], color = 'black', linewidth=1) ax.plot([x1, x1], [y[i]-0.02, y[i]], color = 'black', linewidth=1) ax.plot([x2, x2], [y[i]-0.02, y[i]], color = 'black', linewidth=1) ax.text((x1+x2)/2, y[i], "***", horizontalalignment='center')
ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False)
plt.xticks(fontsize=10) plt.yticks(fontsize=12) plt.ylim(-0.05, 1.00)
plt.tight_layout()
plt.savefig("box_plot.png")
plt.show()
|