def plot_images(dImages, title=None): """ Based on dictionary dVectors, multiple vectors are plotted next to each other. """ numbImages = len(dImages) # init figure fig = plt.figure(figsize=(15, 4)) grid = axes_grid1.AxesGrid(fig, 111, nrows_ncols=(1, numbImages), axes_pad=0.55, # share_all=True, cbar_location="right", cbar_mode="each", cbar_size="5%", cbar_pad="2%",) if title is not None: fig.suptitle(title) # plot vectors from dVectors for idx, (key, relVal) in enumerate(dImages.items()): im = grid[idx].imshow(relVal, cmap='jet') grid[idx].set_title(key) grid[idx].axis('off') grid.cbar_axes[idx].colorbar(im) # finalize figure if title is None: fig.tight_layout() else: fig.tight_layout(rect=[0, 0, 0.95, .95])
def show_and_save_power(people, heatmap, name='power.png'): fig_power = plt.figure() # fig_power.suptitle('Moc', fontsize=12) grid = axes_grid1.AxesGrid( fig_power, 111, nrows_ncols=(1, 2), axes_pad=1, cbar_location="right", cbar_mode="each", cbar_size="5%", cbar_pad="5%", ) im1 = grid[0].imshow(people, cmap='plasma', interpolation='nearest') grid.cbar_axes[0].colorbar(im1) im2 = grid[1].imshow(heatmap, cmap='plasma', interpolation='nearest', vmax=np.max(people)) grid.cbar_axes[1].colorbar(im2) plt.savefig(name, bbox_inches='tight', pad_inches=0.0, dpi=500) plt.show() return fig_power
W1 = model.layers[0].weights[0].numpy() B = model.layers[0].weights[1].numpy() dim = int(W1.shape[1]) W11 = W1[:, 0] W12 = W1[:, 1] W11Im = render.vec2im(W11) W12Im = render.vec2im(W12) # init figure fig = plt.figure() grid = axes_grid1.AxesGrid( fig, 111, nrows_ncols=(1, dim), axes_pad=0.55, share_all=True, cbar_location="right", cbar_mode="each", cbar_size="5%", cbar_pad="2%", ) fig.suptitle('Neural network weights images') # plot weights for i in range(dim): im = grid[i].imshow(render.vec2im(W1[:, i]), cmap='jet') grid[i].set_title('W1{i}'.format(i=i + 1) + ' (bias = {})'.format(round(B[i], 2))) grid[i].axis('off') grid.cbar_axes[i].colorbar(im)
def make_imageGrid(fig, rect=111, **grid_kw): """Create a grid using axesgrid1.AxesGrid. Returns grid """ return axes_grid1.AxesGrid(fig, rect=111, **grid_kw)
#A_list.append([(x[1]+0.0001)/sum([i[1] for i in pb]) for x in pb]) # flipped_A_list=zip(*A_list) # print flipped_A_list A = np.array([pp for pp in A_list]) #the matrix p = PrettyTable() #prettyprint matrix for roar in A: p.add_row(roar) print p.get_string(header=False, border=True) fig = plt.figure() grid = axes_grid1.AxesGrid( fig, 111, nrows_ncols=(1, 2), axes_pad=0.5, cbar_location="right", cbar_mode="each", cbar_size="15%", cbar_pad="5%", ) im0 = grid[0].imshow(A, cmap='gist_yarg', interpolation='nearest') grid.cbar_axes[0].colorbar(im0) plt.show() vals, vecs = eigen(A) vals[0] np.set_printoptions(suppress=True) # supress scientific notation on screen print "Stationary distribution: ", norm(vecs[:, 0]) bigprob = []
def plotFigure(f, opt, canvas): if opt['axesgrid'] is not None: fig = plt.figure(figsize=opt['figSize']) grid = axesgrid.AxesGrid(fig, 111, **opt['axesgrid']) axs = [] for r in range(opt['nrows']): for c in range(opt['ncols']): index = r * opt['ncols'] + c axs.append(grid[index]) axis = canvas[index]['axis'] if 'projection' in axis and axis['projection'] is not None: apy.shell.exit( 'Projection needs to be implemented for the axesgrid (plot.py)' ) elif opt['imagegrid'] is not None: fig = plt.figure(figsize=opt['figSize']) if 'nrows_ncols' not in opt['imagegrid']: opt['imagegrid']['nrows_ncols'] = (opt['nrows'], opt['ncols']) grid = axesgrid.ImageGrid(fig, 111, **opt['imagegrid']) axs = [] for r in range(opt['nrows']): for c in range(opt['ncols']): index = r * opt['ncols'] + c axs.append(grid[index]) axis = canvas[index]['axis'] if 'projection' in axis and axis['projection'] is not None: apy.shell.exit( 'Projection needs to be implemented for the axesgrid (plot.py)' ) elif opt['gridspec'] is not None: # Create a figure using gridspec to get a tight layout fig = plt.figure(figsize=opt['figSize']) gs = mpl.gridspec.GridSpec(opt['nrows'], opt['ncols'], **opt['gridspec']) #if isinstance(opt['gridspec'],dict): # gs.update(**opt['gridspec']) axs = [] for r in range(opt['nrows']): for c in range(opt['ncols']): index = r * opt['ncols'] + c if opt['merge'] and opt['merge'][0] == index: ax = fig.add_subplot(gs[r, :]) axs.append(ax) elif opt['merge'] and opt['merge'][1] == index: continue else: axs.append(plt.subplot(gs[index])) axis = canvas[index]['axis'] if 'projection' in axis and axis['projection'] is not None: apy.shell.exit( 'Projection needs to be implemented for the gridspec (plot.py)' ) else: # Create a figure and plot all subplots fig = plt.figure(figsize=opt['figSize']) axs = [] for r in range(opt['nrows']): for c in range(opt['ncols']): index = r * opt['ncols'] + c projection = '3d' if canvas[index]['subplot'][3] else None figure = fig.add_subplot(opt['nrows'], opt['ncols'], index + 1, projection=projection) axs.append(figure) for canv in canvas: spIndex, spRows, spCols, spXYZ = canv['subplot'] plotSubplot(axs[spIndex], opt, canv, f) if opt['gridspec'] is None and opt['axesgrid'] is None: plt.tight_layout() # Create a new directory and save the figure apy.shell.mkdir(opt['dirResults'], 'u') plt.savefig(opt['fileName'] % f, bbox_inches='tight') # Close figure plt.close(fig)