import pandas as pd import numpy as np import matplotlib.pyplot as plt def abline(slope, intercept): """Plot a line from slope and intercept""" axes = plt.gca() x_vals = np.array(axes.get_xlim()) y_vals = intercept + slope * x_vals plt.plot(x_vals, y_vals, '--') df=pd.read_csv('ccMobTrial4.CSV', sep=',',names=['L','p','Fail','Samples']) dfcoll = (pd.DataFrame(columns=['L','p','Fail','Samples', 'LogicalFailureRate'])) uniqueLValues = df['L'].unique() uniquepValues = df['p'].unique() for L in uniqueLValues: dftemp = df[df['L'] == L] for p in uniquepValues: dftemp2 = dftemp[dftemp['p'] == p] failval = dftemp2['Fail'].sum() sampeval = dftemp2['Samples'].sum() dfcoll = dfcoll.append({'L' : L, 'p' : p, 'Fail' : failval, 'Samples' : sampeval, 'LogicalFailureRate' : failval/sampeval}, ignore_index = True) #print(dfcoll) fig = plt.figure() ps = [] alphas = [] gl = [] for L in uniqueLValues: if p > 0.00: frame = dfcoll[dfcoll['L'] == L] frame = frame[frame['p'] < 0.05] #plt.scatter (frame['L'], np.log(frame['LogicalFailureRate'])) slope, intercept = np.polyfit(np.log(frame['p']), np.log(frame['LogicalFailureRate']), 1) #print(p, ":" , slope/np.log(p)) #ps.append((np.log(p))) #alphas.append(slope) gl.append(slope) plt.scatter(np.log(uniqueLValues), np.log(gl)) gamma, logalpha = np.polyfit(np.log(uniqueLValues), np.log(gl), 1) print("gamma = ", gamma) print("logalpha = " , (logalpha)) abline(gamma, logalpha) plt.show()