#nbi:hide_in
import matplotlib.pyplot as plt
from scipy.stats import norm
import numpy as np
from ipywidgets import interact
#nbi:hide_in
MINX = -3
MAXX = 10
dt = 0.1
x = np.arange(MINX,MAXX,dt)
N01 = norm.pdf(x,0,1) #H_0
#nbi:hide_in
@interact(mu1=(0.,6.,0.25), significance=(0.01,0.5,0.01))
def plot_test(mu1=4.0, significance=0.05):
    alpha = significance
    critical_value = norm.ppf(1-alpha)
    rejectreg_right = np.arange(critical_value, MAXX, dt)
    Nmu1 = norm.pdf(x,mu1,1) # H_1
    power = 1 - norm.cdf(critical_value, mu1)
    
    plt.plot(x, N01, label="$H_0: N(0,1)$")
    plt.plot(x, Nmu1, label="$H_1: N(\mu_1,1)$")
    plt.fill_between(rejectreg_right, norm.pdf(rejectreg_right), color='blue', alpha=0.3, 
                     label="significance = {:0.2f}".format(alpha))
    plt.fill_between(rejectreg_right, norm.pdf(rejectreg_right,mu1,1), 
                     color='orange', alpha=0.3, label="power = {:0.3f}".format(power))
    plt.legend()
    plt.yticks([])
    plt.xticks([critical_value])