import matplotlib.pyplot as plt
import numpy as np
import random
values_groups = [
[1,2, 2.2, 1, 3],
[2.3, 3,3, 4,3, 2, 5,3, 4,3, 6],
[0.4,1.2,2.1,1.6,1.3],
]
x_positions = list(range(1, 4))
colors = ['blue', 'orange', 'green']
markers = ['o','o','o']
labels = [
'A', 'B', 'C'
]
means = [np.mean(values) for values in values_groups]
std_devs = [np.std(values) for values in values_groups]
plt.figure(figsize=(2, 4))
x_modified_groups = []
for i, values in enumerate(values_groups):
x_modified = [x_positions[i] + random.uniform(-0.15, 0.15) for _ in values]
x_modified_groups.append(x_modified)
plt.scatter(x_modified, values, color=colors[i], edgecolor='black',linewidth=0.2, marker=markers[i], label=labels[i], zorder=2)
plt.bar(x_positions, means, yerr=[np.zeros(len(std_devs)), std_devs], capsize=10, color='none', edgecolor='black', zorder=1, linewidth=2, error_kw=dict(lw=2, capthick=2))
plt.tick_params(axis='x', which='both', bottom=False)
plt.gca().spines['top'].set_visible(False)
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['bottom'].set_linewidth(2)
plt.gca().spines['left'].set_linewidth(2)
plt.xlabel('Groups')
plt.ylabel('Value')
plt.xticks(
x_positions,
labels,
)
plt.grid(False)
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon=False)
plt.show()
from statsmodels.stats.multicomp import pairwise_tukeyhsd
df = pd.DataFrame({
'group': np.concatenate([[label] * len(values) for label, values in zip(labels, values_groups)]),
'score': np.concatenate(values_groups)
})
tukey_results = pairwise_tukeyhsd(df['score'], df['group'])
print(tukey_results)
plt.savefig('Sample note.svg',transparent=True, bbox_inches="tight")