def scatter(xAxis,yAxis,title="",xLabel="x",yLabel="y",xTicks=None,yTicks=None,lines=None,show=False): "method to plot the class data and if DEBUG = False save the figure" pyplot.figure(num=title) axes = pyplot.axes() pyplot.hold(True) #pyplot.title(title,fontsize=FONTSIZE) maxValue = 0 minValue = numpy.infty if (type(xAxis[0]) == str): xTicks = xAxis xAxis = numpy.arange(len(xAxis)) if (type(yAxis) == dict): colours = itertools.cycle(["b","g","r","c","m","y","k"]) for name,data in sorted(yAxis.items(),key=lambda x:naturalKeys(x[0])): minValue = min(data+[minValue]) maxValue = max(data+[maxValue]) axes.scatter(xAxis[:len(data)],data[:len(xAxis)],label=name,color=next(colours)) handles, labels = axes.get_legend_handles_labels() l1 = axes.legend(handles,labels,loc=4,fontsize=FONTSIZE) else: axes.scatter(xAxis[:len(yAxis)],yAxis[:len(xAxis)],label="") if xTicks: axes.xticks(xAxis, xTicks, rotation=0) axes.set_xlabel(xLabel,fontsize=FONTSIZE) axes.set_ylabel(yLabel,fontsize=FONTSIZE) #axes.set_title(title,fontsize=FONTSIZE) if lines: for name,line in sorted(lines.items(),key=lambda x:naturalKeys(x[0])): axes.plot(line[0],line[1],label=name,linewidth=1) handles2, labels2 = axes.get_legend_handles_labels() for i in range(len(handles)): handles2.remove(handles[i]) labels2.remove(labels[i]) l2 = axes.legend(handles2,labels2,loc=2,fontsize=FONTSIZE) pyplot.gca().add_artist(l1) pyplot.hold(False) return saveFigure(title,show)
def scatter3(xAxis,yAxis,zAxis,title="",xLabel="x",yLabel="y",zLabel="z",scaleBox=False,show=False): "function to plot a 3d scatter plot" matplotlib.rcParams['legend.fontsize'] = FONTSIZE figure = pyplot.figure(num=title) axes = Axes3D(figure) #axes.set_aspect('equal') if (type(zAxis) == dict): colours = itertools.cycle(["b","g","r","c","m","y","k"]) for name,data in sorted(zAxis.items(),key=lambda x:naturalKeys(x[0])): axes.scatter(xAxis, yAxis, data, label=name, color=next(colours)) axes.legend(fontsize=FONTSIZE) else: axes.scatter(xAxis, yAxis, zAxis, label=title) if scaleBox: addScaleBox(axes,xAxis, yAxis, zAxis) axes.set_xlabel(xLabel,fontsize=FONTSIZE) axes.set_ylabel(yLabel,fontsize=FONTSIZE) axes.set_zlabel(zLabel,fontsize=FONTSIZE) #axes.set_title(title,fontsize=FONTSIZE) return saveFigure(title,show)
def path(paths,title="",xLabel="x",yLabel="y",arrows=None,show=False,tight=True): "function to plot the given paths" figure = pyplot.figure(num=title) axes = pyplot.axes() pyplot.hold(True) #pyplot.title(title) for label,data in sorted(paths.items(),key=lambda x:naturalKeys(x[0])): if len(data) == 3: [x,y,z] = data else: [x,y] = data axes.plot(x[:len(y)],y[:len(x)],label=label) if arrows: for label,data in arrows.items(): [x1,y1,x2,y2] = data axes.arrow(x1,y1,x2,y2,head_width=0.1, fc='k', ec='k') axes.set_xlabel(xLabel,fontsize=FONTSIZE) axes.set_ylabel(yLabel,fontsize=FONTSIZE) #axes.set_title(title,fontsize=FONTSIZE) axes.legend(loc=4) pyplot.hold(False) pyplot.axis('equal') return saveFigure(title,show,tight)
def scatter2(series,title="",xLabel="x",yLabel="y",xTicks=None,yTicks=None,lines=None,location=4,show=False): "method to plot the class data and if DEBUG = False save the figure" pyplot.figure(num=title) axes = pyplot.axes() pyplot.hold(True) #pyplot.title(title,fontsize=FONTSIZE) colours = itertools.cycle(["b","g","r","c","m","y","k"]) for name,data in sorted(series.items(),key=lambda x:naturalKeys(x[0])): axes.scatter(data[0],data[1],label=name,color=next(colours)) for name,data in sorted(lines.items(),key=lambda x:naturalKeys(x[0])): axes.plot(data[0],data[1],label=name,color=next(colours)) axes.set_xlabel(xLabel,fontsize=FONTSIZE) axes.set_ylabel(yLabel,fontsize=FONTSIZE) #axes.set_title(title,fontsize=FONTSIZE) axes.legend(fontsize=FONTSIZE,loc=location) pyplot.hold(False) return saveFigure(title,show)
def path2(paths,title="",xLabel="x",yLabel="y",scatter=None,show=False): "function to plot the given paths" figure = pyplot.figure(num=title) axes = pyplot.axes() pyplot.hold(True) #pyplot.title(title) for label,data in sorted(paths.items(),key=lambda x:naturalKeys(x[0])): [x,y] = data axes.plot(x[:len(y)],y[:len(x)],label=label) if scatter: for name,data in sorted(scatter.items(),key=lambda x:naturalKeys(x[0])): pyplot.scatter(data[0],data[1],label=name) axes.set_xlabel(xLabel,fontsize=FONTSIZE) axes.set_ylabel(yLabel,fontsize=FONTSIZE) #axes.set_title(title,fontsize=FONTSIZE) axes.legend(loc=4) pyplot.hold(False) return saveFigure(title,show)
def bar(labels,values,title="",xLabel="",yLabel="",lines=False,show=False): "plots a bar chart with the givne labels and data values" def plot9(): data = [ ("data1", 34), ("data2", 22), ("data3", 11), ( "data4", 28), ("data5", 57), ( "data6", 39), ("data7", 23), ( "data8", 98)] N = len( data ) x = np.arange(1, N+1) y = [ num for (s, num) in data ] labels = [ s for (s, num) in data ] width = 1 bar1 = plt.bar( x, y, width, color="y" ) plt.ylabel( 'Intensity' ) plt.xticks(x + width/2.0, labels ) plt.show() length = len(values) indexs = numpy.arange(length) barWidth = 1 figure = pyplot.figure(num=title) axes = pyplot.axes() pyplot.hold(True) barAxes = pyplot.bar(indexs,values,barWidth) pyplot.legend(barAxes,labels,fontsize=FONTSIZE) #pyplot.title(title,fontsize=FONTSIZE) labels = [label[:10] for label in labels] pyplot.xticks(indexs + barWidth/2, labels, rotation=0) pyplot.yticks(range(0,max(values)+10,5)) pyplot.xlabel(xLabel,fontsize=FONTSIZE) pyplot.ylabel(yLabel,fontsize=FONTSIZE) if lines: for name,line in sorted(lines.items(),key=lambda x:naturalKeys(x[0]),reverse=True): pyplot.plot([line,line],[0,maxFrequency],label=name,linewidth=1) pyplot.legend() pyplot.hold(False) return saveFigure(title,show)
def histogram(data,title="",xLabel="Value",yLabel="Frequency",lines=None,numberBars=10,show=False): "plots a histogram of the given data data" maxFrequency = len(data)/numberBars pyplot.figure(num=title) pyplot.hold(True) pyplot.hist(data,numberBars) #pyplot.title(title,fontsize=FONTSIZE) pyplot.xlabel(xLabel,fontsize=FONTSIZE) pyplot.ylabel(yLabel,fontsize=FONTSIZE) if lines: for name,line in sorted(lines.items(),key=lambda x:naturalKeys(x[0]),reverse=True): pyplot.plot([line,line],[0,maxFrequency],label=name,linewidth=1) pyplot.legend() pyplot.hold(False) return saveFigure(title,show)
def line(xAxis,yAxis,title="",xLabel="x",yLabel="y",location=4,scatter=None,xTicks=None,yTicks=None,tight=True,show=False): "method to plot the class data and if DEBUG = False save the figure" pyplot.figure(num=title) pyplot.hold(True) #pyplot.title(title) if (type(xAxis[0]) == str): xTicks = xAxis xAxis = numpy.arange(len(xAxis)) if (type(yAxis) == dict): yMin,yMax = 0,0 for name,data in sorted(yAxis.items(),key=lambda x:naturalKeys(x[0])): yMin = min(data+[yMin]) yMax = max(data+[yMax]) pyplot.plot(xAxis[:len(data)],data[:len(xAxis)],label=name) pyplot.legend(fontsize=FONTSIZE,loc=location) else: yMin = min(yAxis) yMax = max(yAxis) pyplot.plot(xAxis[:len(yAxis)],yAxis[:len(xAxis)],label="") if xTicks: pyplot.xticks(xAxis, xTicks, rotation=0) if scatter: for name,data in scatter.items(): pyplot.scatter(data[0],data[1],label=name) pyplot.xlabel(xLabel,fontsize=FONTSIZE) pyplot.ylabel(yLabel,fontsize=FONTSIZE) ySpace = (yMax-yMin)*0.05 pyplot.ylim((yMin-ySpace,yMax+ySpace)) pyplot.hold(False) return saveFigure(title,show,tight)