def generate_violion_plots(plot_col, group_col, group_order, ax):
    
    boxes = []
    mus = []
    stds = []
    g_order = []
    for group in group_order:
        mask = group_col == group
        tmp = plot_col[mask].dropna()
        if len(tmp) > 2:
            g_order.append(group)
            boxes.append(tmp.copy().values)
            mus.append(plot_col[mask].mean())
            stds.append(plot_col[mask].std())
        
    if len(boxes) == 2:
        ef = abs(np.diff(mus))/(np.sum(stds))
        ratio = len(boxes[1])/len(boxes[0])
        n0 = tt_ind_solve_power(effect_size=ef, alpha = alpha, power = power, ratio = ratio)
        sizes = [str(int(n0)), str(int(n0*ratio))]
        _, pval = ttest_ind(*boxes)
    else:
        sizes = ['']*len(boxes)
        _, pval = kruskal(*boxes)
    
    labels = ['%s n=%i/%s' % (t, len(b), n) for t, b, n in zip(g_order, boxes, sizes)]
    violinplot(boxes, ax = ax, labels = labels)
    return pval, ax
df = out_data[haart_mask]
labels.append('cH')
vals = df[check_col].dropna().values
boxes.append(vals[np.isfinite(vals)])

df = out_data[~haart_mask]
labels.append('dH')
vals = df[check_col].dropna().values
boxes.append(vals[np.isfinite(vals)])




plt.figure(figsize = (10, 10))
ax = plt.subplot(111)
_=violinplot(boxes, labels = labels, ax = ax)
ax.set_ylim([0, 8])
plt.savefig('VLfigure.png', dpi = 500)

# <codecell>

from functools import partial

ewma_func = partial(pd.ewma, span=3, freq = '6M')


out = []
for pid, indf in out_data.reset_index().groupby('Patient ID'):
    ndf = indf.set_index('Date')
    tmp = ewma_func(ndf)
    tmp['Patient ID'] = pid
    mus = []
    stds = []
    for trop in trops:
        mask = cyto_data['Tropism'] == trop
        #mask &= cyto_data['Keep']
        boxes.append(cyto_data[col][mask].dropna().values)
        mus.append(cyto_data[col][mask].mean())
        stds.append(cyto_data[col][mask].std())
    
    ef = abs(np.diff(mus))/(np.sum(stds))
    ratio = len(boxes[1])/len(boxes[0])
    n0 = tt_ind_solve_power(effect_size=ef, alpha = alpha, power = power, ratio = ratio)
    sizes = [n0, n0*ratio]
    _, pval = ttest_ind(*boxes)
    labels = ['%s n=%i/%i' % (t, len(b), n) for t, b, n in zip(trops, boxes, sizes)]
    violinplot(boxes, ax = ax, labels = labels)
    # 
    ax.set_title(col + ' pval:%f' % pval)
    ax.set_ylim([0, ax.get_ylim()[1]])
plt.tight_layout()
plt.savefig(base_path+'uncorrected_cyto_data.png')

# <codecell>

fig, axs = plt.subplots(11,3, figsize = (10,20))

for ax, col in zip(axs.flatten(), cytos):
    
    boxes = []
    mus = []
    stds = []