Draw distribution of the Portmanteu whiteness test.

    Parameters
    ----------
    var : :class:`~scot.var.VARBase`-like object
        Vector autoregressive model (VAR) object whose residuals are tested for whiteness.
    h : int
        Maximum lag to include in the test.
    repeats : int, optional
        Number of surrogate estimates to draw under the null hypothesis.
    axis : axis, optional
        Axis to draw into. By default draws into :func:`matplotlib.pyplot.gca()`.

    Returns
    -------
    pr : float
        *p*-value of whiteness under the null hypothesis

def plot_whiteness(var, h, repeats=1000, axis=None):
    """ Draw distribution of the Portmanteu whiteness test.

    Parameters
    ----------
    var : :class:`~scot.var.VARBase`-like object
        Vector autoregressive model (VAR) object whose residuals are tested for whiteness.
    h : int
        Maximum lag to include in the test.
    repeats : int, optional
        Number of surrogate estimates to draw under the null hypothesis.
    axis : axis, optional
        Axis to draw into. By default draws into :func:`matplotlib.pyplot.gca()`.

    Returns
    -------
    pr : float
        *p*-value of whiteness under the null hypothesis
    """
    pr, q0, q = var.test_whiteness(h, repeats, True)

    if axis is None:
        axis = current_axis()

    pdf, _, _ = axis.hist(q0, 30, normed=True, label='surrogate distribution')
    axis.plot([q,q], [0,np.max(pdf)], 'r-', label='fitted model')

    #df = m*m*(h-p)
    #x = np.linspace(np.min(q0)*0.0, np.max(q0)*2.0, 100)
    #y = sp.stats.chi2.pdf(x, df)
    #hc = axis.plot(x, y, label='chi-squared distribution (df=%i)' % df)

    axis.set_title('significance: p = %f'%pr)
    axis.set_xlabel('Li-McLeod statistic (Q)')
    axis.set_ylabel('probability')

    axis.legend()

    return pr