Esempio n. 1
0
def plot_pareto_scenarios(generations, headers, relative, savelocation):
    xs =[]
    ys =[]
    zs =[]
    fig = plt.figure()
    counter = 0
    for header in headers:
        pathX = sFn.pathX(header)
        pop, eps, testedPop = sFn.readCheckPoint(pathX, generations[counter], 0)
        Area_buildings = pd.read_csv(pathX.pathRaw+'//'+'Total.csv',usecols=['Af']).values.sum()
        [x, y, z] = map(np.array, zip( *[ind.fitness.values for ind in pop] ) )
        ax = fig.add_subplot(111)
        if relative == True:
            z[:] = [a / Area_buildings for a in z]
            x[:] = [b / Area_buildings for b in x]
            y[:] = [c / Area_buildings for c in y]
        xs.extend(x)
        ys.extend(y)
        zs.extend(z)
        counter +=1
        
    if relative == True:
        TAC = 'TAC [EU/m2.yr]'
        CO2 = 'CO2 [kg-CO2/m2.yr]'
        PEN = 'PEN [MJ/m2.yr]'
        ax.set_ylim([10,50])
        finallocation = savelocation+"pareto_m2.png"
    else:
        var = 1000000
        zs[:] = [x / var for x in zs]
        xs[:] = [x / var for x in xs]
        ys[:] = [x / var for x in ys]
        TAC = 'TAC [Mio EU/yr]'
        CO2 = 'CO2 [kton-CO2/yr]'
        PEN = 'PEN [TJ/yr]' 
        ax.set_xlim([2.5,7.0]) 
        finallocation = savelocation+"pareto.png"
               
    cm = plt.get_cmap('jet')
    cNorm = matplotlib.colors.Normalize(vmin=min(zs), vmax=max(zs))
    scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
    ax.scatter(xs, ys, c=scalarMap.to_rgba(zs), s=50, alpha =0.8)    
    ax.set_xlabel(TAC)
    ax.set_ylabel(CO2)
    

    scalarMap.set_array(zs)
    fig.colorbar(scalarMap, label=PEN)
    plt.grid(True)
    plt.rcParams['figure.figsize'] = (6,4)
    plt.rcParams.update({'font.size':12})
    plt.gcf().subplots_adjust(bottom=0.15)
    plt.savefig(finallocation)
    plt.clf()
Esempio n. 2
0
def plot_epsilon_scenarios(scenarios, generations, headers):
    colors = ['b','r','y','c']    
    fig = plt.figure()   
    counter = 0    
    for scenario in scenarios:
        epsNorm = norm.normalize_epsIndicator(sFn.pathX(headers[counter]), generations[counter])
        xList = [ 2 + x for x in range(len(epsNorm)) ]
        ax = fig.add_subplot(111)
        ax.plot(xList, epsNorm, colors[counter], label=scenario)
        ax.set_ylabel('Normalized epsilon indicator')
        ax.set_xlabel('Generation No.')
        plt.legend(scenarios, loc='upper right')
        plt.rcParams['figure.figsize'] = (6,4)
        plt.rcParams['font.size'] = 12
        counter +=1
    plt.show()
def plot_buildings_connected_scenarios(scenarios, generations, headers):
    counter = 0
    data = [1, 2, 3, 4]
    colors = ['b', 'r', 'y', 'c']
    fig = plt.figure()
    for header in headers:
        pathX = sFn.pathX(header)
        BuildCon = []
        BuildCon2 = []
        for i in range(generations[counter]):
            i += 1
            pop, eps, testedPop, ntwList, fitness = sFn.readCheckPoint(
                pathX, i, 0)
            buildCon = []
            buildCon2 = []
            for ind in pop:
                buildCon.extend([np.average(ind[21:]) * 100])
                buildCon2.append([np.average(ind[21:]) * 100])

            BuildCon.extend(buildCon)
            BuildCon2.append(np.average(buildCon2))

        data[counter] = BuildCon

        # individual lines per generation
        xList = [1 + x for x in range(len(BuildCon2))]
        ax = fig.add_subplot(111)
        ax.plot(xList, BuildCon2, colors[counter], label=scenarios)
        ax.set_xlim(1, generations[counter])
        ax.set_ylabel('Percentage of buildings connected (%)')
        ax.set_xlabel('Generation No.')
        #ax.set_xticks(np.arange(1,generations[counter]+1,2))
        counter += 1
    plt.legend(scenarios, loc='upper left')
    plt.rcParams['figure.figsize'] = (6, 4)
    plt.rcParams['font.size'] = 12
    plt.show()

    # box plot with all data)
    fig = plt.figure(figsize=(6, 4))
    plt.rcParams['font.size'] = 12
    plt.boxplot(data, 1, 'rs', 0)
    plt.yticks([1, 2, 3, 4], scenarios)
    plt.xlabel("Percentage of buildings connected (%)")
    plt.show()
    return data
def plot_buildings_connected_scenarios(scenarios, generations, headers):
    counter =0    
    data = [1,2,3,4]  
    colors = ['b','r','y','c']
    fig = plt.figure()
    for header in headers:
        pathX = sFn.pathX(header)
        BuildCon = []
        BuildCon2 = []
        for i in range(generations[counter]):
            i += 1
            pop, eps, testedPop = sFn.readCheckPoint(pathX, i, 0)
            buildCon = []
            buildCon2 = []
            for ind in pop:
                buildCon.extend([np.average(ind[21:])*100])
                buildCon2.append([np.average(ind[21:])*100])
                
            BuildCon.extend(buildCon)
            BuildCon2.append(np.average(buildCon2))
            
        data[counter] = BuildCon
    
        # individual lines per generation
        xList = [ 1 + x for x in range(len(BuildCon2)) ]
        ax = fig.add_subplot(111)
        ax.plot(xList, BuildCon2, colors[counter], label=scenarios)
        ax.set_xlim(1,generations[counter])
        ax.set_ylabel('Percentage of buildings connected (%)')
        ax.set_xlabel('Generation No.')
        #ax.set_xticks(np.arange(1,generations[counter]+1,2))
        counter +=1
    plt.legend(scenarios, loc='upper left')        
    plt.rcParams['figure.figsize'] = (6,4)
    plt.rcParams['font.size'] = 12
    plt.show()
    
    # box plot with all data)
    fig = plt.figure(figsize = (6,4))
    plt.rcParams['font.size'] = 12
    plt.boxplot(data,1,'rs',0)  
    plt.yticks([1, 2, 3, 4], scenarios)
    plt.xlabel("Percentage of buildings connected (%)")
    plt.show()
    return data