def plot_convolution(plotname, tsframe, tsframe_max, paperwidth): colormap=plt.get_cmap('YlOrRd_r') colormap.set_under([0.2, 0.2, 0.2]) figure_width = paperwidth figure_height = paperwidth figure_size = [figure_width, figure_height] config.load_config_small() width = tsframe.shape[1]; height = tsframe.shape[0] xs,ys = np.meshgrid(np.arange(0, width+1), np.arange(0, height+1)) fig, axes = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, figsize=figure_size, dpi=100) ax = axes # Workaround inverted y-axis ax.invert_yaxis() # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(xs-0.5, ys-0.5, tsframe, cmap=colormap, vmin=0.1, vmax=tsframe_max, shading="faceted", linestyle="dashed", linewidth=0.5, edgecolor=[0.0, 0.0, 0.0]) # Absolute number #for i,j in ((x,y) for x in np.arange(0, len(tsframe)) # for y in np.arange(0, len(tsframe[0]))): # if tsframe[i][j] >= 1: # ax.annotate(str(int(tsframe[i][j])), xy=(j,i), fontsize=3.5, ha='center', va='center') ax.set_aspect('equal') ax.set_xlim([-0.5, width-0.5]) ax.set_ylim([height-0.5, -0.5]) ax.xaxis.tick_top() ax.tick_params(axis='both', which='both', left='off', right='off', bottom='off', top='off', labeltop='on', pad=1, labelsize=4) #ax.xaxis.set_major_locator(plt.NullLocator()) #ax.yaxis.set_major_locator(plt.NullLocator()) fig.tight_layout() fig.savefig(plotname+".pdf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pdf fig.savefig(plotname+".pgf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pgf
############ # Plotting ########### text_width = 6.30045 # LaTeX text width in inches golden_ratio = (1 + np.sqrt(5)) / 2.0 size_factor = 0.75 figure_width = size_factor * text_width figure_height = (figure_width / golden_ratio) #figure_height = (text_width / golden_ratio) # height is golden ratio to page width #figure_height = 1.3 * figure_width #figure_size = [figure_width, figure_height] figure_size = [figure_width, figure_width] config.load_config_small() # Arbitrary colormap import matplotlib.colors as colors import matplotlib.cm as cmx cdict = { 'red': ((0.0, 0.9, 0.9), (1.0, 0.9, 0.9)), 'green': ((0.0, 0.9, 0.9), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) } #plt.register_cmap(name='YELLOW_RED', data=cdict) #colorMap = plt.get_cmap("YELLOW_RED") colorMap = plt.get_cmap("YlOrRd_r")
fontsize='small', labelspacing=0.5, handletextpad=0.05, columnspacing=0.5, borderpad=0.5, fancybox=True, shadow=False, framealpha=1.0) plotname = "scatterplotmatrix_legend" fig.savefig(plotname+".pdf", pad_inches=0, dpi=fig.dpi) # pdf fig.savefig(plotname+".pgf", pad_inches=0, dpi=fig.dpi) # pgf plt.close() ''' ''' ####################################################### # Bean plot (standardized features) ####################################################### import numpy as np import statsmodels.api as sm import matplotlib.pyplot as plt config.load_config_small() figure_size = [1*text_width, 1*text_height] n_columns = 54 n_rows = 12 # 36 rows = np.array([[0, 12], [12, 24], [24, 36]]) #labels = np.arange(0, 54, 1)
fig.savefig(plotname+".pgf", pad_inches=0, dpi=fig.dpi) # pgf plt.close() ################################## # 2D ################################## figure_width = 0.66*text_width figure_height = figure_width # (figure_width / golden_ratio) #figure_width #figure_height = 0.75 * figure_width figure_size = [figure_width, figure_height] config.load_config_small() # 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) p = 5 x = np.linspace(-1, 1, 256)
def plot_convolution3(plotname, tsframe, paperwidth): colormap = plt.get_cmap('YlOrRd_r') colormap.set_under([0.2, 0.2, 0.2]) figure_width = paperwidth figure_height = paperwidth figure_size = [figure_width, figure_height] config.load_config_small() # find peak and scale neighbourhood poi = np.asarray(np.unravel_index(np.argmax(tsframe), tsframe.shape)) px = poi[1] py = poi[0] r = 1 scalefactor = 4.0 peak_area = tsframe[py - r:py + r + 1, px - r:px + r + 1] peak_area = scipy.ndimage.zoom(peak_area, scalefactor, order=3) # Point of interest of peak_area poi_area = np.asarray( np.unravel_index(np.argmax(peak_area), peak_area.shape)) px_area = poi_area[1] py_area = poi_area[0] offset_x_area = (scalefactor * (2 * r + 1) - 1) / 2.0 - px_area offset_y_area = (scalefactor * (2 * r + 1) - 1) / 2.0 - py_area width = peak_area.shape[1] height = peak_area.shape[0] xs, ys = np.meshgrid(np.arange(0, width + 1), np.arange(0, height + 1)) fig, axes = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, figsize=figure_size, dpi=100) ax = axes # Workaround inverted y-axis ax.invert_yaxis() # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(xs - 0.5, ys - 0.5, peak_area, cmap=colormap, vmin=0.1, vmax=np.max(peak_area), shading="faceted", linestyle="dashed", linewidth=0.5, edgecolor=[0.0, 0.0, 0.0]) # Absolute number #for i,j in ((x,y) for x in np.arange(0, len(tsframe)) # for y in np.arange(0, len(tsframe[0]))): # if tsframe[i][j] >= 1: # ax.annotate(str(int(tsframe[i][j])), xy=(j,i), fontsize=3.5, ha='center', va='center') r = 3.5 #extent1 = patches.Rectangle((-0.48, -0.48), 11.96, 11.96, lw=1.5, ec=[0.0, 0.0, 0.0, 1.0], fc=[1.0, 1.0, 1.0, 0.0], zorder=98 ) #extent2 = patches.Rectangle((-0.48, -0.48), 11.96, 11.96, lw=0.5, ec=[0.0, 0.0, 1.0, 1.0], fc=[0.0, 0.0, 0.0, 0.0], zorder=99 ) #ax.add_patch(extent1) #ax.add_patch(extent2) kernel1 = patches.Rectangle((px_area - r, py_area - r), 2 * r, 2 * r, lw=1.5, ec=[0.0, 0.0, 0.0, 1.0], fc=[1.0, 1.0, 1.0, 0.0]) kernel2 = patches.Rectangle((px_area - r, py_area - r), 2 * r, 2 * r, lw=0.5, ec=[0.0, 1.0, 0.0, 1.0], fc=[0.0, 0.0, 0.0, 0.0]) ax.add_patch(kernel1) ax.add_patch(kernel2) ax.set_aspect('equal') ax.set_xlim([-0.5, width - 0.5]) ax.set_ylim([height - 0.5, -0.5]) #ax.plot(px_area, py_area, "x", ms=2, mew=0.3, color=[1.0, 1.0, 1.0, 1.0], mfc='None') ax.plot(px_area, py_area, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[0.0, 1.0, 0.0, 1.0]) ax.plot(px_area + offset_x_area, py_area + offset_y_area, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[0.0, 0.0, 1.0, 1.0]) ax.xaxis.tick_top() ax.tick_params(axis='both', which='both', left='off', right='off', bottom='off', top='off', labeltop='on', pad=1, labelsize=4) ax.xaxis.set_major_locator(plt.NullLocator()) ax.yaxis.set_major_locator(plt.NullLocator()) fig.tight_layout() fig.savefig(plotname + ".pdf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pdf fig.savefig(plotname + ".pgf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pgf
def plot_convolution2(plotname, tsframe, tsframe_max, paperwidth): colormap = plt.get_cmap('YlOrRd_r') colormap.set_under([0.2, 0.2, 0.2]) figure_width = paperwidth figure_height = paperwidth figure_size = [figure_width, figure_height] config.load_config_small() width = tsframe.shape[1] height = tsframe.shape[0] xs, ys = np.meshgrid(np.arange(0, width + 1), np.arange(0, height + 1)) fig, axes = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, figsize=figure_size, dpi=100) ax = axes # Workaround inverted y-axis ax.invert_yaxis() # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(xs - 0.5, ys - 0.5, tsframe, cmap=colormap, vmin=0.1, vmax=tsframe_max, shading="faceted", linestyle="dashed", linewidth=0.5, edgecolor=[0.0, 0.0, 0.0]) # Absolute number #for i,j in ((x,y) for x in np.arange(0, len(tsframe)) # for y in np.arange(0, len(tsframe[0]))): # if tsframe[i][j] >= 1: # ax.annotate(str(int(tsframe[i][j])), xy=(j,i), fontsize=3.5, ha='center', va='center') #find peak poi = np.asarray(np.unravel_index(np.argmax(tsframe), tsframe.shape)) px = poi[1] py = poi[0] ax.plot(px, py, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[0.0, 0.0, 1.0, 1.0]) ax.plot(px - 1, py, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) ax.plot(px + 1, py, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) ax.plot(px, py - 1, "o", ms=1.52, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) ax.plot(px, py + 1, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) cx = (tsframe.shape[1] - 1) / 2 cy = (tsframe.shape[0] - 1) / 2 ax.plot(cx, cy, "x", ms=2, mew=0.3, color=[1.0, 1.0, 1.0, 1.0], mfc='None') r = 1.5 kernel1 = patches.Rectangle((px - r, py - r), 2 * r, 2 * r, lw=1.5, ec=[0.0, 0.0, 0.0, 1.0], fc=[1.0, 1.0, 1.0, 0.0]) kernel2 = patches.Rectangle((px - r, py - r), 2 * r, 2 * r, lw=0.5, ec=[0.0, 0.0, 1.0, 1.0], fc=[0.0, 0.0, 0.0, 0.0]) ax.add_patch(kernel1) ax.add_patch(kernel2) ax.set_aspect('equal') ax.set_xlim([-0.5, width - 0.5]) ax.set_ylim([height - 0.5, -0.5]) ax.xaxis.tick_top() ax.tick_params(axis='both', which='both', left='off', right='off', bottom='off', top='off', labeltop='on', pad=1, labelsize=4) #ax.xaxis.set_major_locator(plt.NullLocator()) #ax.yaxis.set_major_locator(plt.NullLocator()) fig.tight_layout() fig.savefig(plotname + ".pdf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pdf fig.savefig(plotname + ".pgf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pgf
def plot_convolution(plotname, tsframe, tsframe_max, paperwidth): colormap = plt.get_cmap('YlOrRd_r') colormap.set_under([0.2, 0.2, 0.2]) figure_width = paperwidth figure_height = paperwidth figure_size = [figure_width, figure_height] config.load_config_small() width = tsframe.shape[1] height = tsframe.shape[0] xs, ys = np.meshgrid(np.arange(0, width + 1), np.arange(0, height + 1)) fig, axes = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, figsize=figure_size, dpi=100) ax = axes # Workaround inverted y-axis ax.invert_yaxis() # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(xs - 0.5, ys - 0.5, tsframe, cmap=colormap, vmin=0.1, vmax=tsframe_max, shading="faceted", linestyle="dashed", linewidth=0.5, edgecolor=[0.0, 0.0, 0.0]) # Absolute number #for i,j in ((x,y) for x in np.arange(0, len(tsframe)) # for y in np.arange(0, len(tsframe[0]))): # if tsframe[i][j] >= 1: # ax.annotate(str(int(tsframe[i][j])), xy=(j,i), fontsize=3.5, ha='center', va='center') ax.set_aspect('equal') ax.set_xlim([-0.5, width - 0.5]) ax.set_ylim([height - 0.5, -0.5]) ax.xaxis.tick_top() ax.tick_params(axis='both', which='both', left='off', right='off', bottom='off', top='off', labeltop='on', pad=1, labelsize=4) #ax.xaxis.set_major_locator(plt.NullLocator()) #ax.yaxis.set_major_locator(plt.NullLocator()) fig.tight_layout() fig.savefig(plotname + ".pdf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pdf fig.savefig(plotname + ".pgf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pgf
def plot_convolution3(plotname, tsframe, paperwidth): colormap=plt.get_cmap('YlOrRd_r') colormap.set_under([0.2, 0.2, 0.2]) figure_width = paperwidth figure_height = paperwidth figure_size = [figure_width, figure_height] config.load_config_small() # find peak and scale neighbourhood poi = np.asarray(np.unravel_index(np.argmax(tsframe), tsframe.shape)) px = poi[1] py = poi[0] r = 1 scalefactor = 4.0 peak_area = tsframe[py-r:py+r+1, px-r:px+r+1] peak_area = scipy.ndimage.zoom(peak_area, scalefactor, order=3) # Point of interest of peak_area poi_area = np.asarray(np.unravel_index(np.argmax(peak_area), peak_area.shape)) px_area = poi_area[1] py_area = poi_area[0] offset_x_area = (scalefactor*(2*r+1)-1)/2.0 - px_area offset_y_area = (scalefactor*(2*r+1)-1)/2.0 - py_area width = peak_area.shape[1]; height = peak_area.shape[0] xs,ys = np.meshgrid(np.arange(0, width+1), np.arange(0, height+1)) fig, axes = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, figsize=figure_size, dpi=100) ax = axes # Workaround inverted y-axis ax.invert_yaxis() # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(xs-0.5, ys-0.5, peak_area, cmap=colormap, vmin=0.1, vmax=np.max(peak_area), shading="faceted", linestyle="dashed", linewidth=0.5, edgecolor=[0.0, 0.0, 0.0]) # Absolute number #for i,j in ((x,y) for x in np.arange(0, len(tsframe)) # for y in np.arange(0, len(tsframe[0]))): # if tsframe[i][j] >= 1: # ax.annotate(str(int(tsframe[i][j])), xy=(j,i), fontsize=3.5, ha='center', va='center') r = 3.5 #extent1 = patches.Rectangle((-0.48, -0.48), 11.96, 11.96, lw=1.5, ec=[0.0, 0.0, 0.0, 1.0], fc=[1.0, 1.0, 1.0, 0.0], zorder=98 ) #extent2 = patches.Rectangle((-0.48, -0.48), 11.96, 11.96, lw=0.5, ec=[0.0, 0.0, 1.0, 1.0], fc=[0.0, 0.0, 0.0, 0.0], zorder=99 ) #ax.add_patch(extent1) #ax.add_patch(extent2) kernel1 = patches.Rectangle((px_area-r, py_area-r), 2*r, 2*r, lw=1.5, ec=[0.0, 0.0, 0.0, 1.0], fc=[1.0, 1.0, 1.0, 0.0] ) kernel2 = patches.Rectangle((px_area-r, py_area-r), 2*r, 2*r, lw=0.5, ec=[0.0, 1.0, 0.0, 1.0], fc=[0.0, 0.0, 0.0, 0.0] ) ax.add_patch(kernel1) ax.add_patch(kernel2) ax.set_aspect('equal') ax.set_xlim([-0.5, width-0.5]) ax.set_ylim([height-0.5, -0.5]) #ax.plot(px_area, py_area, "x", ms=2, mew=0.3, color=[1.0, 1.0, 1.0, 1.0], mfc='None') ax.plot(px_area, py_area, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[0.0, 1.0, 0.0, 1.0]) ax.plot(px_area+offset_x_area, py_area+offset_y_area, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[0.0, 0.0, 1.0, 1.0]) ax.xaxis.tick_top() ax.tick_params(axis='both', which='both', left='off', right='off', bottom='off', top='off', labeltop='on', pad=1, labelsize=4) ax.xaxis.set_major_locator(plt.NullLocator()) ax.yaxis.set_major_locator(plt.NullLocator()) fig.tight_layout() fig.savefig(plotname+".pdf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pdf fig.savefig(plotname+".pgf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pgf
def plot_convolution2(plotname, tsframe, tsframe_max, paperwidth): colormap=plt.get_cmap('YlOrRd_r') colormap.set_under([0.2, 0.2, 0.2]) figure_width = paperwidth figure_height = paperwidth figure_size = [figure_width, figure_height] config.load_config_small() width = tsframe.shape[1]; height = tsframe.shape[0] xs,ys = np.meshgrid(np.arange(0, width+1), np.arange(0, height+1)) fig, axes = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, figsize=figure_size, dpi=100) ax = axes # Workaround inverted y-axis ax.invert_yaxis() # pcolormesh aligns cells on their edges, while imshow aligns them on their centers. ax.pcolormesh(xs-0.5, ys-0.5, tsframe, cmap=colormap, vmin=0.1, vmax=tsframe_max, shading="faceted", linestyle="dashed", linewidth=0.5, edgecolor=[0.0, 0.0, 0.0]) # Absolute number #for i,j in ((x,y) for x in np.arange(0, len(tsframe)) # for y in np.arange(0, len(tsframe[0]))): # if tsframe[i][j] >= 1: # ax.annotate(str(int(tsframe[i][j])), xy=(j,i), fontsize=3.5, ha='center', va='center') #find peak poi = np.asarray(np.unravel_index(np.argmax(tsframe), tsframe.shape)) px = poi[1] py = poi[0] ax.plot(px, py, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[0.0, 0.0, 1.0, 1.0]) ax.plot(px-1, py, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) ax.plot(px+1, py, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) ax.plot(px, py-1, "o", ms=1.52, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) ax.plot(px, py+1, "o", ms=1.5, mew=0.3, mec=[0.0, 0.0, 0.0, 1.0], mfc=[1.0, 1.0, 1.0, 1.0]) cx = (tsframe.shape[1]-1)/2 cy = (tsframe.shape[0]-1)/2 ax.plot(cx, cy, "x", ms=2, mew=0.3, color=[1.0, 1.0, 1.0, 1.0], mfc='None') r = 1.5 kernel1 = patches.Rectangle((px-r, py-r), 2*r, 2*r, lw=1.5, ec=[0.0, 0.0, 0.0, 1.0], fc=[1.0, 1.0, 1.0, 0.0] ) kernel2 = patches.Rectangle((px-r, py-r), 2*r, 2*r, lw=0.5, ec=[0.0, 0.0, 1.0, 1.0], fc=[0.0, 0.0, 0.0, 0.0] ) ax.add_patch(kernel1) ax.add_patch(kernel2) ax.set_aspect('equal') ax.set_xlim([-0.5, width-0.5]) ax.set_ylim([height-0.5, -0.5]) ax.xaxis.tick_top() ax.tick_params(axis='both', which='both', left='off', right='off', bottom='off', top='off', labeltop='on', pad=1, labelsize=4) #ax.xaxis.set_major_locator(plt.NullLocator()) #ax.yaxis.set_major_locator(plt.NullLocator()) fig.tight_layout() fig.savefig(plotname+".pdf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pdf fig.savefig(plotname+".pgf", pad_inches=0, bbox_inches='tight', dpi=fig.dpi) # pgf
# Create legend from custom artist/label lists #plt.figlegend([artist for artist in artists_category], [label for label in unique_labels], # fontsize='x-small', labelspacing=0.5, handletextpad=0.05, # loc='center right', bbox_to_anchor=(0, 0.5, 1, 1), bbox_transform=plt.gcf().transFigure ) legend = plt.legend([artist for artist in artists_category], [label for label in unique_labels], ncol=3, loc='center', fontsize='small', labelspacing=0.5, handletextpad=0.05, columnspacing=0.5, borderpad=0.5, fancybox=True, shadow=False, framealpha=1.0) plotname = "scatterplotmatrix_legend" fig.savefig(plotname+".pdf", pad_inches=0, dpi=fig.dpi) # pdf fig.savefig(plotname+".pgf", pad_inches=0, dpi=fig.dpi) # pgf plt.close() ''' ''' ####################################################### # Bean plot (standardized features) ####################################################### import numpy as np import statsmodels.api as sm import matplotlib.pyplot as plt config.load_config_small() figure_size = [1*text_width, 1*text_height] n_columns = 54 n_rows = 12 # 36 rows = np.array([[0, 12], [12, 24], [24, 36]]) #labels = np.arange(0, 54, 1)