import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns


plt.rcParams.update(
    {
        "figure.figsize": (10, 6),
        "axes.titlesize": 20,
        "axes.labelsize": 15,
        "legend.fontsize": 15,
        "axes.grid": True,
        "axes.axisbelow": True,
        "pcolor.shading": "auto",
    }
)

    
def plot_ab(control, treatment):
    sns.histplot(control, color='darkblue', stat='density', alpha=0.2)
    sns.kdeplot(control, color='darkblue', linewidth=4, label="Control")

    sns.histplot(treatment, color='darkorange', stat='density', alpha=0.2)
    sns.kdeplot(treatment, color='darkorange', linewidth=4, label="Treatment")

    plt.legend()
    plt.xlabel("success ratio")
    plt.ylabel("")
    plt.show()


def plot_delta(delta):
    bins = np.arange(
        np.floor(delta.min() * 100)/100,
        np.ceil(delta.max() * 100)/100,
        .001
    )
    sns.histplot(delta[delta<0], label=r"$\Delta$<0", color='red', bins=bins)
    sns.histplot(delta[delta>0], label=r"$\Delta$>0", color='green', bins=bins)
    plt.legend()
    plt.xlabel(r"$\Delta$ success ratio")
    plt.ylabel("")
    plt.show()