import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from plotstyle import *

if __name__ == "__main__":
    n = 21
    nn = 10000
    maxl = 5
    
    indices = np.arange(n)
    rng = np.random.RandomState(19281)
    x1 = rng.rand(n)
    rng = np.random.RandomState(35281)
    x2 = rng.rand(n)
    rng = np.random.RandomState(35281)
    x3 = rng.rand(n)

    x = rng.rand(nn)
    lags = np.arange(-maxl, maxl+1, 1)
    corrs = [np.corrcoef(x[maxl:-maxl-1-l], x[maxl+l:-maxl-1])[0, 1] for l in lags]

    fig = plt.figure(figsize=cm_size(figure_width, 1.8*figure_height))
    spec = gridspec.GridSpec(nrows=2, ncols=2, **adjust_fs(fig))
    
    ax = fig.add_subplot(spec[0, 0])
    ax.plot(indices, x1, zorder=10, **lpsAm)
    ax.set_xlabel('Index')
    ax.set_ylabel('Random number')
    ax.set_xlim(-1.0, n+1.0)
    ax.set_ylim(-0.05, 1.05)
    
    ax = fig.add_subplot(spec[0, 1])
    ax.plot(indices, x2, zorder=10, **lpsAm)
    ax.set_xlabel('Index')
    ax.set_ylabel('Random number')
    ax.set_xlim(-1.0, n+1.0)
    ax.set_ylim(-0.05, 1.05)
    
    ax = fig.add_subplot(spec[1, 1])
    ax.plot(indices, x3, zorder=10, **lpsAm)
    ax.set_xlabel('Index')
    ax.set_ylabel('Random number')
    ax.set_xlim(-1.0, n+1.0)
    ax.set_ylim(-0.05, 1.05)
    
    ax = fig.add_subplot(spec[1, 0])
    ax.plot(lags, corrs, zorder=10, **lpsBm)
    ax.set_xlabel('Lag')
    ax.set_ylabel('Serial correlation')
    ax.set_xlim(-maxl-0.5, maxl+0.5)
    ax.set_ylim(-0.05, 1.05)

    fig.savefig("randomnumbers.pdf")
    plt.close()