# Snippet exactly as printed on the page
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy import stats

d = pd.read_csv("superplot_data.csv")
means = d.groupby(["experiment", "condition"])["speed"].mean().unstack()  # one mean per experiment
res = stats.ttest_rel(means["drug"], means["control"])                     # n = experiments
print(res, res.confidence_interval())

colours = dict(zip(means.index, ["#E69F00", "#56B4E9", "#009E73", "#CC79A7"]))
markers = dict(zip(means.index, ["o", "s", "^", "D"]))
x = {"control": 0, "drug": 1}
rng = np.random.default_rng(1)
fig, ax = plt.subplots(figsize=(4.2, 4.2))
for (e, c), g in d.groupby(["experiment", "condition"]):
    ax.scatter(x[c] + rng.uniform(-0.28, 0.28, len(g)), g["speed"], s=9,
               color=colours[e], marker=markers[e], alpha=0.45, linewidths=0)
for e in means.index:
    ax.plot([0, 1], means.loc[e, ["control", "drug"]], color=colours[e])
    ax.scatter([0, 1], means.loc[e, ["control", "drug"]], s=110, color=colours[e],
               marker=markers[e], edgecolors="black", zorder=3, label=e)
for c in x:
    ax.hlines(means[c].mean(), x[c] - 0.32, x[c] + 0.32, color="black", lw=2, zorder=4)
ax.set_xticks([0, 1], ["Control", "Drug"])
ax.set_ylabel("Cell speed (µm/min)")
ax.legend(title="Experiment", frameon=False)
fig.savefig("page_snippet.svg")
