import os
import matplotlib.pyplot as plt
results = {}

def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
    ax = ax if ax is not None else plt.gca()
    if color is None:
        color = ax._get_lines.color_cycle.next()
    ymin, ymax = yerr
    ax.plot(x, y, color=color)
    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)


def generate(l, la = 0.992, init = 0.01):
    axis = []
    resu = []
    resu_bars_mini = []
    resu_bars_maxi = []
    NB_IT = 15
    for i in range(10, 500, 25):
        results[i] = []
        axis.append(i)
        mini  =10
        maxi = 0
        for j in range(NB_IT):
            os.system('./main '+str(l)+" "+str(i)+ " 2 1000 "+ str(la)+ " "+ str(init)+ " > res")
            r = open("res", "r")
            res = float(r.readline())
            mini = min(res, mini)
            maxi = max(res, maxi)
            results[i].append(res)
        resu.append(sum(results[i])/NB_IT)
        resu_bars_mini.append(mini)
        resu_bars_maxi.append(maxi)

    resu_bars = [resu_bars_mini, resu_bars_maxi]
    print results
    print axis
    print resu
    print resu_bars

    #plt.errorbar(axis, resu, resu_bars, fmt='o')

    #errorfill(axis, resu, resu_bars)


generate(2, 0.99, 0.1)
generate(2, 0.99, 0.01)
generate(2, 0.99, 0.001)
generate(2, 0.99, 0.0001)
generate(2, 0.99, 0.00001)

errorfill(axis, resu, resu_bars)

plt.show()
