def singlebargraph(xv, yvs,title, folder='Bargraphs',xlabel='', ylabel='',xticks = None): rectlist = [] N = len(xv) ind = numpy.arange(N) #colors = ['w','r', 'y', 'b', 'g','c'] if len(yvs) == 0: return width = 8.0/36 if xticks == None: xticks = xv def autolabel(rects): for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2, 1.05*height, "", ha='center', va='bottom') fig, ax = plt.subplots(figsize = (8, 6)) rect1 = ax.bar(ind, yvs, width, color = 'b') rectlist.append(rect1) autolabel(rect1) ax.legend() #ax.set_title(title) ax.set_xticklabels(xv) plt.ylabel(ylabel) plt.xlabel(xlabel) plt.subplots_adjust(bottom=0.15) xticks_pos = [0.5*patch.get_width() + patch.get_xy()[0] for patch in rect1] plt.xticks(xticks_pos, xticks, ha = "center", rotation='horizontal') myutils.createDir(folder) plt.savefig(folder+"/" + title+".pdf") plt.close()
def linegraph2(title, xlabel, ylabel, means, stds, folder): fig = plt.figure(figsize=(4, 3)) xv1 = range(len(means)) plt.errorbar([0.15, 1.15], means[0], yerr = stds[0], label="Upload Speed", fmt='s') plt.errorbar([0.3, 1.3], means[1], yerr = stds[1], label="Download Speed", fmt='o') #plt.scatter(xv1, means[0], marker="s") #plt.scatter(xv1, means[1], marker="o") #plt.xlabel(xlabel) plt.ylabel(ylabel) #plt.title(title) plt.xticks([0.2, 1.2], xlabel, ha = "center") ax = plt.subplot(111) #ax.plot(marker="s") ax.legend() #plt.yticks(numpy.arange(0, 34, 5)) fn = title + "Linegraph" fn = fn.replace(" ", "") fn = fn.replace("/","") gd = os.path.join(folder, "Linegraphs") myutils.createDir(gd) fn = os.path.join(gd, fn+".pdf") plt.savefig(fn) plt.close()
def scatterploto(xv, yvss,title,folder, xlabel='', ylabel='',labels=None,rotation='0',islog=False,stds=None): fig = plt.figure(figsize=(6, 4.5)) xv1 = range(len(xv)) xinc = 0.5/len(yvss) markers=['s', 'o', 'x', '^','v', '<', '>' ] for i in range(len(yvss)): marker = markers[i%len(markers)] xv1 = [ x + xinc for x in xv1] yvs = yvss[i] label = labels[i] if labels is not None else '' std = stds[i] if stds is not None else [0 for x in range(len(xv1))] plt.errorbar(xv1, yvs, yerr = stds, label=label, fmt=marker) #plt.errorbar([1,3], umeans, yerr = ustds, label="Upload Speed in Mbits/sec", fmt='o') params = {'legend.fontsize': 6, 'legend.linewidth': 2} plt.rcParams.update(params) #plt.scatter(xv1,yvs,)#, marker="s") plt.xlabel(xlabel) plt.ylabel(ylabel) plt.title(title) plt.xticks(numpy.array([x+xinc*len(yvss)/2.0 for x in range(len(xv))]), xv, ha = "center", rotation=rotation) ax = plt.subplot(111) ax.legend() #plt.yticks(numpy.arange(0, 34, 5)) #plt.xscale('log') #plt.yscale('log') fn = title + "Linegraph" fn = fn.replace(" ", "") fn = fn.replace("/","") gd = os.path.join(folder, "Linegraphs") myutils.createDir(gd) fn = os.path.join(gd, fn+".pdf") plt.savefig(fn) plt.close()
def singlestackedbargraph(xv, yvss,title, folder='Bargraphs',xlabel='', ylabel='', legend=None, rotation = '0',islog=False, stds=None, ylimit=None, iscolor=False): rectlist = [] N = len(xv) ind = numpy.arange(N) colors = ['b', 'g', 'r','k','c','y', '#CC0C0', '0CCCCC'] #if not iscolor: # colors = ['w', 'w', 'w','w', 'w', 'w', 'w', 'w'] patterns = ['.']#'"x", "o", "O", ".", "*", "/" , "\\" , "|" , "-" , "+" , ] if len(yvss[0]) == 0: return if len(xv) > 5: width = 6.0/(len(xv)*2) else: width = 6.0/10 def autolabel(rects): for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2, 1.05*height, "", ha='center', va='bottom') fig, ax = plt.subplots(figsize = (6, 4)) i=0 bottom = [0 for x in range(len(yvss[0]))] for yvs in yvss: std = None if stds is not None: std = stds[i] rect1 = ax.bar(ind, yvs, width, color=colors[i%6], bottom=bottom,yerr=std, hatch=patterns[i%len(patterns)]) else: rect1 = ax.bar(ind, yvs, width, color=colors[i%6], bottom=bottom)#, hatch=patterns[i%len(patterns)]*3) rectlist.append(rect1) autolabel(rect1) i +=1 newbottom = [bottom[x] + yvs[x] for x in range(len(bottom))] bottom = newbottom #ax.set_title(title) ax.set_xticklabels(xv) plt.ylabel(ylabel) if ylimit is not None: plt.ylim(ax, ylimit) plt.xlabel(xlabel) if islog: ax.set_yscale('log') if legend is not None: ax.legend(rectlist, legend, loc='upper right') plt.subplots_adjust(bottom=0.15) xticks_pos = [0.5*patch.get_width() + patch.get_xy()[0] for patch in rectlist[i/2]] plt.xticks(xticks_pos, xv, ha = "center", rotation=rotation) myutils.createDir(folder) filname = title.replace(' ','' ) plt.savefig(folder+"/" + filname+".pdf") plt.close()
def bargraphs(xv, yvss,title, folder='Bargraphs',xlabel='', ylabel='', legend=None, rotation = '0',islog=False, stds=None, loc='upper right', ylimit=None,legendposition='upper right',noxlabel=False, thick=False): rectlist = [] N = len(xv) ind = numpy.arange(N) colors = ['b', 'c', 'r','g' 'm', 'y','k','c'] if len(yvss[0]) == 0: return wx = len(xv) if wx < 6: wx = 6 width = 6.0/(wx*len(yvss)*2) if thick: width = width*4 def autolabel(rects): for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2, 1.05*height, "", ha='center', va='bottom') fig, ax = plt.subplots(figsize = (6, 4)) i=0 for yvs in yvss: std = None if stds is not None: std = stds[i] rect1 = ax.bar(ind+width*i, yvs, width, color=colors[i%6], yerr=std, edgecolor="none") else: rect1 = ax.bar(ind+width*i, yvs, width, color=colors[i%6], edgecolor="none") rectlist.append(rect1) autolabel(rect1) i +=1 #ax.set_title(title) if not noxlabel: ax.set_xticklabels(xv) plt.ylabel(ylabel) plt.xlabel(xlabel) if ylimit is not None: plt.ylim(ylimit) if islog: ax.set_yscale('log') if legend is not None: ax.legend(rectlist, legend, loc=loc) plt.subplots_adjust(bottom=0.15) if i%2 == 0: xticks_pos = [patch.get_xy()[0] for patch in rectlist[i/2]] else: xticks_pos = [0.5*patch.get_width() + patch.get_xy()[0] for patch in rectlist[i/2]] if not noxlabel: plt.xticks(xticks_pos, xv, ha = "center", rotation=rotation) myutils.createDir(folder) filname = title.replace(' ','' ) plt.savefig(folder+"/" + filname+".pdf") plt.close()
def linegraph(title, xlabel, ylabel, legends, xv, yvs, folder, xlog = False, ylog = False, same= False,legendposition='upper right'): fig = plt.figure(figsize=(10,6)) gr = False for i in range(len(yvs)): yv = yvs[i] k = legends[i] #print xv, yv if len(yv) < len(xv): for i in range(len(xv) - len(yv)): yv.append(0) elif len(yv) < len(xv) or len(xv) == 0 or len(yv) == 0: continue #print xv, yv, len(xv), len(yv) try: #xv, yv = sortlists(xv, yv) plt.plot(xv, yv, label = k) gr = True except: pass if not gr: try: plt.close() return except: return plt.xlabel(xlabel) plt.ylabel(ylabel) plt.legend(loc=legendposition, fontsize=10) plt.title(title) if xlog: plt.xscale('log') if ylog: plt.yscale('log') ax = plt.subplot(111) #plt.yscale('log') fn = title + "Linegraph" fn = fn.replace(" ", "") fn = fn.replace("/","") gd = os.path.join(folder, "Linegraphs") myutils.createDir(gd) fn = os.path.join(gd, fn+".pdf") plt.savefig(fn) plt.close()
def map2D(title, xlabel, ylabel, xv, yv, folder, same = False): if len(xv) is 0 or len(yv) is 0: return #print "xv: ", xv #print "yv: ", yv fig = plt.figure(figsize = (8,5)) plt.plot(xv, yv,"ro") plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) #plt.xscale('log') #plt.yscale('log') #print min(xv), max(xv) #plt.axis([min(xv)/10, max(xv)*10, 0, (float(max(yv)))]) fn = title xm = max(xv) ym = max(yv) if xm>ym: mx = xm else: mx = ym xm = min(xv) ym = min(yv) if xm>ym: mn = ym else: mn = xm fn = fn.replace(" ", "") fn = fn.replace("/","") gd = os.path.join(folder, "Map2D") myutils.createDir(gd) fn = os.path.join(gd, fn+".pdf") if same == True and xm is not None and ym is not None: plt.axis([mn,float(mx), mn, float(mx)]) plt.savefig(fn) plt.close()