def plot_pdf(pdfs, budget, out_file): CommonConf.setupMPPDefaults() fig, axes = pp.subplots(2, len(solvers)/2, sharex=True, sharey=True, figsize=(12,6)) colors=CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() xs = np.asarray([float(i+1)/budget for i in range(budget)]) width = 1. print xs axeslist = [] print axes for ax in axes: print ax axeslist = axeslist + list(ax) for ax,solver in zip(axeslist, sorted(solvers)): zorder = 1 pdf = pdfs[solver] print solver, pdf ys = [] for x in xs: y = sum([pdf[k] for k in pdf.keys() if k <= (x+0.001) and k >= (x-0.24)]) #(k > (x-min_x) ys.append(y) print sum(ys) print ys ax.bar(np.arange(len(xs))-0.5, ys, width, alpha=1.0, color=[colors[solver]]*len(xs), edgecolor='white',#[colors[solver]]*len(xs), label=CommonConf.gen_label(solver), linewidth=0,#linewidth[solver], linestyle='solid', #marker=mrkrs[solver], #markersize=mrkrsize[solver], zorder=1/np.mean(ys)) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') ax.locator_params(axis='x', nbins=4) ax.locator_params(axis='y', nbins=4) ax.set_xlabel("Risk"); ax.set_ylabel("Probability"); ax.legend(loc='best', borderaxespad=0., fancybox=True, ncol=3) pp.locator_params(axis='x', nbins=6) pp.xticks(np.arange(len(xs)), xs) pp.xlim(-0.5,3.5) pp.tight_layout(pad=0) pp.savefig("tmp.pdf")
def main(dirn, fname, solvers): (xs, ysPerSolver, ydevsPerSolver) = CommonViz.parseData(dirn, fname, solvers) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(8, 6)) ax = fig.add_subplot(111) # ax.set_xscale("log", basex=2) #xs.append(max(xs)+2) for (solver, ys), (solver, ydevs) in zip(ysPerSolver.iteritems(), ydevsPerSolver.iteritems()): if solver not in CommonConf.solver_list: continue xs_arr = np.asarray(xs) xs_arr = xs_arr + random.random() / 2 xs_arr[-1] += random.random() * 2 avg_y, std_y = np.mean(np.asarray(ys)), np.std(np.asarray(ys)) #ys.append(avg_y) #ydevs.append(std_y) ax.errorbar(xs_arr[1:NUMTM], ys[1:NUMTM], yerr=ydevs[1:NUMTM], alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=mrkrs[solver], markersize=mrkrsize[solver]) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) #ax.set_yscale("log", nonposy='clip') ax.legend(loc='best', borderaxespad=0., fancybox=True, ncol=3) pp.subplots_adjust(left=0.12, right=0.95, top=0.9, bottom=0.12) pp.xlim(0, NUMTM) pp.savefig(dirn + "/" + fname + "-".join(solvers) + ".pdf")
def main(dirn, fname, solvers): (xs, ysPerSolver, ydevsPerSolver) = CommonViz.parseData(dirn, fname, solvers) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(12, 6)) ax = fig.add_subplot(111) # ax.set_xscale("log", basex=2) index = 0 #xs.append(max(xs)+2) for (solver, ys), (solver, ydevs) in zip(ysPerSolver.iteritems(), ydevsPerSolver.iteritems()): xs_arr = np.asarray(xs) xs_arr = xs_arr + random.random() / 10 ax.errorbar(xs_arr, ys, yerr=ydevs, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=mrkrs[solver], markersize=mrkrsize[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.legend(loc=0, borderaxespad=1., fancybox=True) ymin, ymax = pp.ylim() pp.ylim(0.5, 1.05) xa = ax.get_xaxis() xa.set_major_locator(pylab.MaxNLocator(integer=True)) #ax.annotate('link (s2-s12) fails', xy=(1.8, 0.54), xytext=(0.95, 0.6), # arrowprops=dict(facecolor='black', shrink=0.05), fontsize=14 # ) #pp.axvline(1.8, linestyle='dashed' ) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) #pp.savefig(dirn+"/"+fname+"-".join(solvers)+".pdf") pp.savefig(dirn + "/" + fname + "-".join(solvers) + ".svg")
def plot_resilience(paths_dir, out_file): fig = pp.figure(figsize=(12,8)) ax = fig.add_subplot(111) paths_file = dict() resilience = dict() rects = dict() width = 0.9/len(algs) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() bar_width = 0.7 for alg in algs: paths_file[alg] = paths_dir + '/' + alg + '_0' for alg in algs: mhs_vals = [] paths = parse_path_file(paths_file[alg]) for sd,sdpaths in paths.iteritems(): mhs = find_min_hitting_set([set(p) for p in sdpaths.keys()]) #print len(sdpaths), len(mhs) mhs_vals.append(len(mhs)-1) resilience[alg] = freq(mhs_vals) t = [max(resilience[alg].keys()) for alg in algs] xs = np.arange(max(t)+1) i = 0 for alg in algs: ys = [] for x in xs: ys.append(np.sum([resilience[alg].get(X,0) for X in xs if X >= x])) print alg, ys rects[alg] = ax.bar(xs-0.5+i*width, ys, width, color=colors[alg], edgecolor=None, alpha=0.8, zorder=1/np.mean(ys)) i = i+1 ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') pp.xticks(range(len(algs)), [' ' for x in algs]) ax.locator_params(axis='y', nbins=6) ax.set_ylabel('Number of f-resilient node pairs') ax.set_xticklabels(xs) ax.legend([rects[x] for x in algs], [CommonConf.gen_label(x) for x in algs], loc='best', borderaxespad=1., fancybox=True) pp.xlim(0.5,2.5) pp.tight_layout() pp.savefig("resilience.pdf")
def display(all_congestions, directory): sort_cong = OrderedDict() for scheme in sorted(all_congestions.keys()): sort_cong[scheme] = get_scheme_congestions(all_congestions, scheme) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(12, 6)) ax = fig.add_subplot(111) mxl = 0 num_sample = 20 for solver, cong_dist in sort_cong.iteritems(): ys = [x / len(cong_dist) for x in range(0, len(cong_dist))] gap = int(len(ys) / num_sample) + 1 xx = [] yy = [] for i in range(0, len(ys)): if (i % gap == 0): xx.append(cong_dist[i]) yy.append(ys[i]) if (len(ys) - 1) % gap != 0: xx.append(cong_dist[-1]) yy.append(ys[-1]) ydevs = [0] * len(yy) ax.errorbar(xx, yy, yerr=ydevs, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=mrkrs[solver], markersize=mrkrsize[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.legend(bbox_to_anchor=(1., 1.), loc=2, borderaxespad=1., fancybox=True) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) pp.ylim(0.2, 1.01) pp.savefig(directory + "/CongestionCDF.svg")
def display (all_congestions, directory): sort_cong = OrderedDict() for scheme in sorted(all_congestions.keys()): sort_cong[scheme] = get_scheme_congestions(all_congestions, scheme) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(12,6)) ax = fig.add_subplot(111) mxl = 0 num_sample=20 for solver, cong_dist in sort_cong.iteritems(): ys = [x/len(cong_dist) for x in range(0, len(cong_dist))] gap=int(len(ys)/num_sample)+1 xx=[] yy=[] for i in range(0,len(ys)): if (i%gap==0): xx.append(cong_dist[i]) yy.append(ys[i]) if (len(ys)-1)%gap!=0: xx.append(cong_dist[-1]) yy.append(ys[-1]) ydevs = [0] * len(yy) ax.errorbar(xx, yy, yerr=ydevs, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=mrkrs[solver], markersize=mrkrsize[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.legend(bbox_to_anchor=(1., 1.), loc=2, borderaxespad=1., fancybox=True) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) pp.ylim(0.2,1.01) pp.savefig(directory+"/CongestionCDF.svg")
def main(dirn, fname, solvers): (xs, ysPerSolver, ydevsPerSolver) = CommonViz.parseData(dirn, fname, solvers) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(12,6)) ax = fig.add_subplot(111) # ax.set_xscale("log", basex=2) index = 0 #xs.append(max(xs)+2) for (solver, ys), (solver, ydevs) in zip(ysPerSolver.iteritems(),ydevsPerSolver.iteritems()) : xs_arr = np.asarray(xs) xs_arr = xs_arr + random.random()/10 ax.errorbar(xs_arr, ys, yerr=ydevs, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=mrkrs[solver], markersize=mrkrsize[solver]) ax.set_xlabel(X_LABEL); ax.set_ylabel(Y_LABEL); ax.legend(loc=0, borderaxespad=1., fancybox=True) ymin, ymax = pp.ylim() pp.ylim(0.5,1.05) xa = ax.get_xaxis() xa.set_major_locator(pylab.MaxNLocator(integer=True)) #ax.annotate('link (s2-s12) fails', xy=(1.8, 0.54), xytext=(0.95, 0.6), # arrowprops=dict(facecolor='black', shrink=0.05), fontsize=14 # ) #pp.axvline(1.8, linestyle='dashed' ) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) #pp.savefig(dirn+"/"+fname+"-".join(solvers)+".pdf") pp.savefig(dirn+"/"+fname+"-".join(solvers)+".svg")
def main(dirn, fname, solvers): (xs, ysPerSolver, ydevsPerSolver) = CommonViz.parseData(dirn, fname, solvers) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(12, 6)) ax = fig.add_subplot(111) # ax.set_xscale("log", basex=2) xs.append(max(xs) + 2) for (solver, ys), (solver, ydevs) in zip(ysPerSolver.iteritems(), ydevsPerSolver.iteritems()): xs_arr = np.asarray(xs) xs_arr = xs_arr + random.random() / 2 xs_arr[-1] += random.random() * 2 avg_y, std_y = np.mean(np.asarray(ys)), np.std(np.asarray(ys)) ys.append(avg_y) ydevs.append(std_y) ax.errorbar( xs_arr, ys, yerr=ydevs, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=mrkrs[solver], markersize=mrkrsize[solver], ) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.legend(bbox_to_anchor=(1.0, 1.0), loc=2, borderaxespad=1.0, fancybox=True) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) pp.savefig(dirn + "/" + fname + "-".join(solvers) + ".svg")
def main(dirn, fname, solvers): (xs, ysPerSolver, ydevsPerSolver) = CommonViz.parseData(dirn, fname, solvers) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(12, 6)) ax = fig.add_subplot(111) # ax.set_xscale("log", basex=2) xs.append(max(xs) + 2) for (solver, ys), (solver, ydevs) in zip(ysPerSolver.iteritems(), ydevsPerSolver.iteritems()): xs_arr = np.asarray(xs) xs_arr = xs_arr + random.random() / 2 xs_arr[-1] += random.random() * 2 avg_y, std_y = np.mean(np.asarray(ys)), np.std(np.asarray(ys)) ys.append(avg_y) ydevs.append(std_y) ax.errorbar(xs_arr, ys, yerr=ydevs, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linestyle=fmts[solver], linewidth=linewidth[solver], marker=mrkrs[solver], markersize=mrkrsize[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.legend(bbox_to_anchor=(1., 1.), loc=2, borderaxespad=1., fancybox=True) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) pp.savefig(dirn + "/" + fname + "-".join(solvers) + ".svg")
def display (all_latencies, directory): # all_latencies : solver -> #tm(0-23) -> path_len -> frac_traffic scheme_latency_dist = OrderedDict() # solver -> path_length -> (frac_tput_mean, frac_tput_std) for solver in all_latencies.keys(): lat_percentile = get_latency_percentile(all_latencies, solver) scheme_latency_dist[solver] = lat_percentile CommonConf.setupMPPDefaults() fmts = CommonConf.getLineFormatsDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() mrkrlw = CommonConf.getLineMarkersLWDict() colors = CommonConf.getLineColorsDict() fig = pp.figure(figsize=(6,5)) ax = fig.add_subplot(111) max_lat = 0 for solver, latencies in scheme_latency_dist.iteritems(): max_lat = max(max_lat, max(latencies.keys())) gap=1 for solver, latencies in scheme_latency_dist.iteritems(): xs = [] xsall = sorted(latencies.keys()) for i in range(0,len(xsall)): if (i%gap==0): xs.append(xsall[i]) if (len(xsall)-1)%gap!=0: xs.append(xsall[-1]) ys = [latencies[lat][0] for lat in xs] ydevs = [latencies[lat][1] for lat in xs] ax.plot((xs[-1], max_lat), (ys[-1], ys[-1]), linestyle=':', marker=mrkrs[solver], color=colors[solver], markersize=mrkrsize[solver], markerfacecolor='none', markeredgecolor=colors[solver], markeredgewidth=mrkrsize[solver]/4, linewidth=mrkrlw[solver]) new_xs = np.linspace(min(xs), max(xs), (max(xs)-min(xs))*3+1) print new_xs yinterp = pchip(xs, ys) ydevsinterp = pchip(xs, ydevs) new_ys = yinterp(new_xs) new_ydevs = ydevsinterp(new_xs) ax.errorbar(new_xs, new_ys, yerr=new_ydevs, label=CommonConf.gen_label(solver), marker=mrkrs[solver], linestyle=fmts[solver], color=colors[solver], markersize=mrkrsize[solver], markerfacecolor='none', markeredgecolor=colors[solver], markeredgewidth=mrkrsize[solver]/4, markevery=len(new_xs)/4, errorevery=len(new_xs)/4, linewidth=mrkrlw[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') ax.legend(loc='best', borderaxespad=1., fancybox=True) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) pp.ylim(0.0,1.05) xmin,xmax = ax.get_xlim() xmax = (xmax + (xmax%2)) pp.xlim(3, xmax) pp.tight_layout() pp.savefig(directory+"/LatencyCDF.svg")
def display( all_latencies, directory ): # all_latencies : solver -> #tm(0-23) -> path_len -> frac_traffic scheme_latency_dist = OrderedDict( ) # solver -> path_length -> (frac_tput_mean, frac_tput_std) for solver in all_latencies.keys(): lat_percentile = get_latency_percentile(all_latencies, solver) scheme_latency_dist[solver] = lat_percentile CommonConf.setupMPPDefaults() fmts = CommonConf.getLineFormatsDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() mrkrlw = CommonConf.getLineMarkersLWDict() colors = CommonConf.getLineColorsDict() fig = pp.figure(figsize=(9, 6)) ax = fig.add_subplot(111) max_lat = 0 for solver, latencies in scheme_latency_dist.iteritems(): max_lat = max(max_lat, max(latencies.keys())) gap = 1 for solver, latencies in scheme_latency_dist.iteritems(): if solver not in solver_list: continue xs = [] xsall = sorted(latencies.keys()) for i in range(0, len(xsall)): if (i % gap == 0): xs.append(xsall[i]) if (len(xsall) - 1) % gap != 0: xs.append(xsall[-1]) ys = [latencies[lat][0] for lat in xs] ydevs = [latencies[lat][1] for lat in xs] # ax.plot((xs[-1], max_lat), (ys[-1], ys[-1]), linestyle=':', # marker=mrkrs[solver], # color=colors[solver], # markersize=mrkrsize[solver], # markerfacecolor='none', # markeredgecolor=colors[solver], # markeredgewidth=mrkrsize[solver]/4, # linewidth=mrkrlw[solver]) new_xs = np.linspace(min(xs), max(xs), (max(xs) - min(xs)) * 3 + 1) print new_xs yinterp = pchip(xs, ys) ydevsinterp = pchip(xs, ydevs) new_ys = yinterp(new_xs) new_ydevs = ydevsinterp(new_xs) ax.errorbar( new_xs, new_ys, # yerr=new_ydevs, label=CommonConf.gen_label(solver), # marker=mrkrs[solver], linestyle=fmts[solver], color=colors[solver], markersize=mrkrsize[solver], markerfacecolor='none', markeredgecolor=colors[solver], markeredgewidth=mrkrsize[solver] / 4, markevery=None, # len(new_xs)/20, errorevery=len(new_xs) / 20, linewidth=mrkrlw[solver]) ax.fill_between(new_xs, new_ys - new_ydevs, new_ys + new_ydevs, facecolor=colors[solver], alpha=0.3, interpolate=True, edgecolor=colors[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') ax.legend(loc='best', borderaxespad=0., fancybox=True) pp.subplots_adjust(left=0.1, right=0.8, top=0.9, bottom=0.1) pp.ylim(0.0, 1.05) xmin, xmax = ax.get_xlim() xmax = (xmax + (xmax % 2)) pp.xlim(3, 350) pp.tight_layout(pad=0) pp.savefig(directory + "/LatencyCDF.pdf")
def plot_latency(rtt_file, paths_dir, out_file, rtt_hop): paths_file = dict() for alg in algs: paths_file[alg] = paths_dir + '/' + alg + '_0' rtts = parse_rtt_file(rtt_file) alg_sd_wtrtt = defaultdict(dict) # alg -> sd -> weighted_rtt for alg in algs: paths = parse_path_file(paths_file[alg]) for sd, sdpaths in paths.iteritems(): weighted_rtts = 0 for path, weight in sdpaths.iteritems(): path_rtt = 0 if rtt_hop == 'rtt': for link in path: path_rtt += rtts.get(link, 0) else: path_rtt = len(path) - 2 weighted_rtts += weight * path_rtt alg_sd_wtrtt[alg][sd] = weighted_rtts # sort hosts by ecmp weighted RTT sorted_sd = sorted(alg_sd_wtrtt['ecmp'].items(), key=operator.itemgetter(1)) sorted_sd = [x[0] for x in sorted_sd] alg_sorted_lats = dict( ) # alg -> list of latencies sorted by ecmp distance for alg in algs: if alg == BASE: alg_sorted_lats[alg] = [alg_sd_wtrtt[BASE][sd] for sd in sorted_sd] else: alg_sorted_lats[alg] = [ (alg_sd_wtrtt[alg][sd] - 0 * alg_sd_wtrtt[BASE][sd]) for sd in sorted_sd ] setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() for solver in algs: fig = pp.figure(figsize=(12, 6)) ax = fig.add_subplot(111) #if solver == BASE: # continue ys = alg_sorted_lats[solver] print solver if solver == 'ecmp' or solver == 'edksp': markeredgecolor = colors[solver] else: markeredgecolor = 'None' ax.plot( #alg_sorted_lats[BASE], ys, alpha=0.5, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle='None', markevery=1, markeredgecolor=markeredgecolor, markeredgewidth=mrkrsize[solver] / 4, marker=mrkrs[solver], markersize=mrkrsize[solver] * 1.5) ax.set_xlabel("Node Pairs") if rtt_hop == 'rtt': ax.set_ylabel("RTT (ms)") else: ax.set_ylabel("hop count") ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') ax.xaxis.set_ticks([]) # handles, labels = ax.get_legend_handles_labels() # # or sort them by labels # hl = sorted(zip(handles, labels), key=operator.itemgetter(1)) # hl = hl[1:5]+[hl[0]]+[hl[5]] # Put racke in correct position # handles2, labels2 = zip(*hl) # ax.legend(handles2, labels2, loc='best', borderaxespad=0., fancybox=True, ncol=3) pp.locator_params(nbins=4) pp.tight_layout(pad=0) pp.savefig(out_file.split('.')[0] + solver + '.pdf')
def display(all_congestions, snapshot, directory, outfile): sort_cong = OrderedDict() for scheme in sorted(all_congestions.keys()): sort_cong[scheme] = get_scheme_congestions(all_congestions, snapshot, scheme) CommonConf.setupMPPDefaults() colors = CommonConf.getLineColorsDict() fmts = CommonConf.getLineFormatsDict() linewidth = CommonConf.getLineMarkersLWDict() mrkrs = CommonConf.getLineMarkersDict() mrkrsize = CommonConf.getLineMarkersSizeDict() fig = pp.figure(figsize=(9, 6)) ax = fig.add_subplot(111) mxl = 0 num_sample = 1000 for solver, cong_dist in sort_cong.iteritems(): if solver not in CommonConf.solver_list: continue ys = [x / len(cong_dist) for x in range(0, len(cong_dist))] gap = int(len(ys) / num_sample) + 1 xx = [] yy = [] for i in range(0, len(ys)): if (i % gap == 0): xx.append(cong_dist[i]) yy.append(1 - ys[i]) if (len(ys) - 1) % gap != 0: xx.append(cong_dist[-1]) yy.append(1 - ys[-1]) ydevs = [0] * len(yy) #ax.errorbar(xx, yy, yerr=ydevs, # alpha=0.8, # color=colors[solver], # label=CommonConf.gen_label(solver), # linewidth=linewidth[solver], # linestyle=fmts[solver], # marker=None,#mrkrs[solver], # markersize=mrkrsize[solver]) ax.plot( xx, yy, alpha=0.8, color=colors[solver], label=CommonConf.gen_label(solver), linewidth=linewidth[solver], linestyle=fmts[solver], marker=None, #mrkrs[solver], markersize=mrkrsize[solver]) ax.set_xlabel(X_LABEL) ax.set_ylabel(Y_LABEL) ax.legend(loc='best', borderaxespad=0., fancybox=True) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') #pp.subplots_adjust(left=0.2, right=0.95, top=0.95, bottom=0.15) xmax = pp.xlim()[1] if xmax > 1: ax.set_xlabel(X_EXPLABEL) ax.set_xscale("log", nonposx='clip') ax.set_yscale("log", nonposx='clip') print pp.xlim() xmax = pp.xlim()[1] ax.xaxis.set_major_formatter(ScalarFormatter()) #ax.yaxis.set_major_formatter(ScalarFormatter()) ax.axvline(x=1, color='r', lw=2, ls='-') currentAxis = pp.gca() currentAxis.add_patch( Rectangle((1, 0), xmax, 1, facecolor="red", alpha=0.05)) pp.xlim(1e-2, 1e2) pp.ylim(1e-4, 1e0) pp.tight_layout(pad=0) pp.savefig(directory + "/" + outfile + ".pdf")