def linePlotFunction(function, start, stop, step, title, xlabel, ylabel, fileNamePostfix=''): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) points = np.arange(start, stop, step) transformedPoints = list(map(function, points)) ax.plot(points, transformedPoints) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) title = title + fileNamePostfix plt.savefig('plots/beamer/' + title.replace(' ', '') + '.pdf', format='pdf', bbox_inches='tight') #plt.show() plt.close(fig)
def plotAsLineInc(dataList, labeling, title, std=None, fileNamePostfix=''): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) markers = itertools.cycle(('--s', '--x', '--^', '--o', '--*')) for num, data in enumerate(dataList): data_y = data data_x = np.arange(len(data)) + 1 data_y = np.round(data_y * 100, decimals=1) ax.plot(data_x, data_y, next(markers), label=labeling[num]) if std: curStd = std[num] curStd = np.round(curStd * 100, decimals=1) print(curStd) ax.fill_between(data_x, data_y - curStd, data_y + curStd, alpha=0.3) ax.set_ylim([0, 100]) ax.set_xlabel(r'Class Increment') ax.set_ylabel(r'F1\%') ax.set_title(title) ax.legend().get_frame().set_alpha(0.5) title = title + fileNamePostfix plt.savefig('plots/beamer/' + title.replace(' ', '') + '.pdf', format='pdf', bbox_inches='tight') plt.close(fig)
def plotAsBarRepr(data, xLabeling, hidLegend, title, std=None, numberPoints=4, fileNamePostfix=''): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) #transform to percentage data = np.round(data * 100, decimals=1) if np.any(std): std = np.round(std * 100, decimals=1) totalGroups = len(data) / numberPoints print(totalGroups) totalGroups = int(totalGroups) data = np.reshape(data, (totalGroups, -1)) std = np.reshape(std, (totalGroups, -1)) width = 0.27 allRects = [] for ind, subData in enumerate(data): indices = np.arange(numberPoints) + 1 rects = ax.bar(indices + (ind - 1) * width, subData, width, yerr=std[ind]) allRects.append(rects) ax.set_xticks(indices) ax.set_xticklabels(xLabeling, minor=False) colors = mpl.cm.get_cmap(name='Paired') for j, rects in enumerate(allRects): for i, rect in enumerate(rects): colorIndex = j rect.set_facecolor(colors(colorIndex)) ax.set_ylim([0, 100]) ax.set_xlabel(r'Mel Bins') ax.set_ylabel(r'F1\%') ax.set_title(title) if hidLegend: legIndices = list( map( int, np.linspace(0, len(allRects), num=len(hidLegend), endpoint=False))) print(legIndices) legList = [] for ind in legIndices: legList.append(allRects[ind][0]) ax.legend(legList, hidLegend) title = title + fileNamePostfix plt.savefig('plots/beamer/' + title.replace(' ', '') + '.pdf', format='pdf', bbox_inches='tight') plt.close(fig)
def plotAsBarReprOld(data, xLabeling, hidLegend, title, std=None, numberPoints=4, fileNamePostfix=''): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) ind = np.arange(len(data)) + 1 #transform to percentage data = np.round(data * 100, decimals=1) if np.any(std): std = np.round(std * 100, decimals=1) rects1 = ax.bar(ind, data, yerr=std) ax.set_xticks(ind) ax.set_xticklabels(xLabeling, minor=False) #colors=['r','y','g'] colors = mpl.cm.get_cmap(name='Paired') #.to_rgba(np.arange(3)) for i, rect in enumerate(rects1): if hidLegend: if len(hidLegend) < 3: colorIndex = (i + numberPoints) // numberPoints else: colorIndex = i // numberPoints else: colorIndex = i // numberPoints rect.set_facecolor(colors(colorIndex)) ax.set_ylim([25, 90]) ax.set_xlabel(r'Mel Bins') ax.set_ylabel(r'F1\%') ax.set_title(title) if hidLegend: legIndices = list( map( int, np.linspace(0, len(rects1), num=len(hidLegend), endpoint=False))) print(legIndices) legList = [] for ind in legIndices: legList.append(rects1[ind]) ax.legend(legList, hidLegend) title = title + fileNamePostfix plt.savefig('plots/beamer/' + title.replace(' ', '') + '.pdf', format='pdf', bbox_inches='tight') plt.close(fig)
def plotAsLinePlot(data, basefile, maxNum): for num, example in enumerate(data): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthThesis), num=num) plt.plot(example.T) plt.savefig(basefile + str(num) + '.pdf', format='pdf', bbox_inches='tight') plt.close(fig) if num > maxNum: break
def scatterNoveltyPlotWithLabel(data, labelArray, novelIndex, legend, title, fileNamePostfix=''): fig, (ax1, ax2) = plt.subplots(1, 2, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) colorMap = mpl.cm.get_cmap(name='Paired') maxLabel = np.max(labelArray) colorsArray = colorMap(labelArray / maxLabel, alpha=1) nonNovelData = data[labelArray < novelIndex] nonNovelLabels = colorsArray[labelArray < novelIndex] ax1.scatter(nonNovelData[:, 0], nonNovelData[:, 1], c=nonNovelLabels, edgecolors='k', s=20) ax2.scatter(data[:, 0], data[:, 1], c=colorsArray, edgecolors='k', s=20) ax1.tick_params(axis='both', bottom=False, left=False, labelbottom=False, labelleft=False) ax2.tick_params(axis='both', bottom=False, left=False, labelbottom=False, labelleft=False) ax2.set_alpha(0.1) ax1.set_title('Training time') ax2.set_title('Testing time') title = title + fileNamePostfix plt.savefig('plots/beamer/' + title.replace(' ', '') + '.pdf', format='pdf', bbox_inches='tight') #plt.show() plt.close(fig)
def plotAsPcolor(data, basefile, maxNum, ylabel='Mel-bin'): for num, example in enumerate(data): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthThesis), num=num) plt.pcolormesh(example.T, edgecolor='none', rasterized=True, cmap='magma') ax.axvline(x=50) ax.set_ylabel(ylabel) ax.set_xlabel('Frames') plt.savefig(basefile + str(num) + '.pdf', format='pdf', bbox_inches='tight') plt.close(fig) if num > maxNum: break
def plot2DHelper(self, fileName, nodeDataArray, edgesDataArray, labelArray, edgeNodeMapArray): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) colorMap = mpl.cm.get_cmap(name='Paired') maxLabel = numpy.max(labelArray) colorsArray = colorMap(labelArray / maxLabel, alpha=1) classes = range(int(maxLabel) + 1) classNames = [ 'background', 'clearthroat', 'cough', 'doorslam', 'drawer', 'keyboard', 'keys', 'knock', 'laughter', 'pageturn', 'phone', 'speech' ] class_colours = list( map(colorMap, map(lambda x: x / (maxLabel * 1.0), classes))) recs = [] for i in range(0, len(class_colours)): recs.append( mpl.patches.Rectangle((0, 0), 1, 1, fc=class_colours[i])) plt.scatter(nodeDataArray[:, 0], nodeDataArray[:, 1], c=colorsArray, edgecolors='k', s=20) plt.legend(recs, classes, loc='best').get_frame().set_alpha(0.5) ax.tick_params(axis='both', bottom=False, left=False, labelbottom=False, labelleft=False) plt.savefig(fileName, format='pdf', bbox_inches='tight') for i in range(0, edgesDataArray.shape[0], 2): plt.plot(edgesDataArray[i:i + 2, 0], edgesDataArray[i:i + 2, 1], c=colorsArray[int(edgeNodeMapArray[i])]) plt.savefig(fileName[:-4] + '_withEdges.pdf', format='pdf', bbox_inches='tight') plt.close(fig)
def plotAsLineNodeF1(dataList, labeling, title, fileNamePostfix=''): fig, ax = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) markers = itertools.cycle(('--s', '--x', '--^', '--o', '--*')) for num, data in enumerate(dataList): data_x, data_y = data data_y = np.round(data_y * 100, decimals=1) ax.plot(data_x, data_y, next(markers), label=labeling[num]) ax.set_ylim([20, 100]) ax.set_xlabel(r'Number Nodes') ax.set_ylabel(r'F1\%') ax.set_title(title) ax.legend() title = title + fileNamePostfix plt.savefig('plots/beamer/' + title.replace(' ', '') + '.pdf', format='pdf', bbox_inches='tight') plt.close(fig)
#ax2.pcolor(labels,edgecolor='none',rasterized=True) #vline1 = ax1.axvline(x=0) #vline2 = ax2.axvline(x=0) #plt.savefig(basefile+str(num)+'.png') #ax1.set_ylabel('Mel Bins') #ax2.set_ylabel('Event Label') #ax2.set_xlabel('Frames') #plt.savefig('plots/beamer/fullLength.pdf', format='pdf', bbox_inches='tight') #plt.close(fig) #actualEvents = np.nonzero(labels[0:5,:]) #labels[actualEvents] = labels[actualEvents] + 1 labels[0:maxLabel + 1, :] = labels[0:maxLabel + 1, :] + 0.25 fig, ax2 = plt.subplots(1, 1, figsize=latexFormatPlotter.set_size( latexFormatPlotter.textwidthBeamer)) #ax1.pcolor(spec,edgecolor='none',rasterized=True,cmap='magma') #TODO: plot call on ax object instead? ax2.pcolor(labels, edgecolor='none', rasterized=True) #vline1 = ax1.axvline(x=0) #vline2 = ax2.axvline(x=0) #plt.savefig(basefile+str(num)+'.png') #ax1.set_ylabel('Mel Bins') ax2.set_ylabel('Event Label') ax2.set_xlabel('Frames') plt.savefig('plots/beamer/withHalfIncreased.pdf', format='pdf', bbox_inches='tight') plt.close(fig) fig, ax2 = plt.subplots(1, 1,