text_width = 6.30045 # LaTeX text width in inches golden_ratio = (1 + np.sqrt(5) ) / 2.0 size_factor = 1.0 figure_width = size_factor*text_width figure_height = (figure_width / golden_ratio) #figure_height = 1.3 * figure_width figure_size = [figure_width, figure_height] config.load_config_medium() #-------------------------------------------------------------------------------------------- # Temporal filters (misc) #-------------------------------------------------------------------------------------------- fig = plt.figure(figsize=figure_size) ax = plt.subplot(111) ax.plot(x, y, linestyle="", color=[0.2, 0.2, 0.2, 1.0], zorder=10, label='Mean of active taxels', marker='o', markersize=4.0, markeredgewidth=0.5, markerfacecolor=[1.0, 1.0, 1.0, 1.0], markeredgecolor=[0, 0, 0, 1.0]) ax.plot(x, y_filtered['running_mean'], '-', linewidth=1.5, color=config.UIBK_orange, alpha=1.0, label='Running Mean (N = 5)') ax.plot(x, y_filtered['gaussian'], '-', linewidth=1.5, color=[0.0, 0,0, 0.0], alpha=1.0, label=r'Gaussian Filter ($\sigma$ = 3)')
def plot_confusion_matrix(confusion_matrix, classes, appendix): size_factor = 1.0 figure_width = size_factor*text_width figure_size = [figure_width, figure_width] config.load_config_medium() # Normalize by the number of samples in each class confusion_normalized = confusion_matrix.astype('float') / confusion_matrix.sum(axis=1)[:, np.newaxis] plt.ioff() # Disable interactive plotting fig = plt.figure(figsize=figure_size, dpi=100) ax = fig.add_subplot(111) n_classes = len(classes) ax.axis([0, n_classes, 0, n_classes]) ax.invert_yaxis() ax.set_aspect('equal') # Normalize by the number of samples in each class confusion_normalized = confusion_matrix.astype('float') / confusion_matrix.sum(axis=1)[:, np.newaxis] colormap = plt.get_cmap('UIBK_ORANGES') colormap.set_under([1.0, 1.0, 1.0]) # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(confusion_normalized, cmap=colormap, vmin=0.001, vmax=1.0) #plt.colorbar(mesh) # Absolute number for i,j in ((x,y) for x in np.arange(0, len(confusion_matrix))+0.5 for y in np.arange(0, len(confusion_matrix[0]))+0.5): if confusion_matrix[i][j] > 0: ax.annotate(str(confusion_matrix[i][j]), xy=(j,i), fontsize=4, ha='center', va='center') plt.tick_params(axis='x', which='minor', bottom='off', top='off', labelbottom='on') plt.tick_params(axis='y', which='minor', left='off', right='off', labelleft='on') plt.tick_params(axis='x', which='major', bottom='on', top='off', labelbottom='on', direction='out') plt.tick_params(axis='y', which='major', left='on', right='off', labelleft='on', direction='out') # Set the major ticks at the centers and minor tick at the edges tick_marks = np.arange(n_classes) ax.xaxis.set_ticks(tick_marks, minor=True) ax.yaxis.set_ticks(tick_marks, minor=True) plt.xticks(tick_marks+0.5, classes, rotation=90, rotation_mode='anchor', ha='right', va='center') plt.yticks(tick_marks+0.5, classes) ax.grid(True, which='minor', linestyle='-') # Grid at minor ticks plt.title("Confusion Matrix", y=1.02) plt.xlabel("Predicted class") plt.ylabel("Actual class") plt.tight_layout() plotname = "confusion_matrix_" + appendix fig.savefig(plotname+".pdf", pad_inches=0, dpi=fig.dpi) # pdf #fig.savefig(plotname+".pgf", pad_inches=0, dpi=fig.dpi) # pgf #fig.savefig(plotname+".png", pad_inches=0, dpi=300) plt.close(fig)
cdict = {'red': ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 1.0, 1.0), (1.0, 0.5, 0.5)), 'blue': ((0.0, 1.0, 1.0), (1.0, 0.0, 0.0))} plt.register_cmap(name='UIBK_ORANGES', data=cdict) ''' ####################################################### # Scatterplot Matrix ####################################################### # Create discrete colors from continuous colormap import matplotlib.colors as colors import matplotlib.cm as cmx colorNorm = colors.Normalize(vmin=0, vmax=n_classes-1) scalarMap = cmx.ScalarMappable(norm=colorNorm, cmap=plt.get_cmap("jet")) colors = scalarMap.to_rgba(np.arange(0, n_classes), alpha = 0.5) # Markers markers = np.array(['o', 's', '^', 'd', 'D', '*'])
text_height = 9.25737 # LaTeX text height in inches golden_ratio = (1 + np.sqrt(5)) / 2.0 brewer_red = [0.89411765, 0.10196078, 0.10980392] brewer_blue = [0.21568627, 0.49411765, 0.72156863] brewer_green = [0.30196078, 0.68627451, 0.29019608] # Custom colormap UIBK Orange cdict = { 'red': ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 1.0, 1.0), (1.0, 0.5, 0.5)), 'blue': ((0.0, 1.0, 1.0), (1.0, 0.0, 0.0)) } plt.register_cmap(name='UIBK_ORANGES', data=cdict) ''' ####################################################### # Scatterplot Matrix ####################################################### # Create discrete colors from continuous colormap import matplotlib.colors as colors import matplotlib.cm as cmx colorNorm = colors.Normalize(vmin=0, vmax=n_classes-1) scalarMap = cmx.ScalarMappable(norm=colorNorm, cmap=plt.get_cmap("jet")) colors = scalarMap.to_rgba(np.arange(0, n_classes), alpha = 0.5) # Markers markers = np.array(['o', 's', '^', 'd', 'D', '*'])