Python mpl_toolkits.axes_grid1.AxesGrid() Examples
The following are 6
code examples of mpl_toolkits.axes_grid1.AxesGrid().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mpl_toolkits.axes_grid1
, or try the search function
.
Example #1
Source File: demo_edge_colorbar.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def demo_bottom_cbar(fig): """ A grid of 2x2 images with a colorbar for each column. """ grid = AxesGrid(fig, 121, # similar to subplot(132) nrows_ncols=(2, 2), axes_pad=0.10, share_all=True, label_mode="1", cbar_location="bottom", cbar_mode="edge", cbar_pad=0.25, cbar_size="15%", direction="column" ) Z, extent = get_demo_image() cmaps = [plt.get_cmap("autumn"), plt.get_cmap("summer")] for i in range(4): im = grid[i].imshow(Z, extent=extent, interpolation="nearest", cmap=cmaps[i//2]) if i % 2: cbar = grid.cbar_axes[i//2].colorbar(im) for cax in grid.cbar_axes: cax.toggle_label(True) cax.axis[cax.orientation].set_label("Bar") # This affects all axes as share_all = True. grid.axes_llc.set_xticks([-2, 0, 2]) grid.axes_llc.set_yticks([-2, 0, 2])
Example #2
Source File: demo_edge_colorbar.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def demo_right_cbar(fig): """ A grid of 2x2 images. Each row has its own colorbar. """ grid = AxesGrid(F, 122, # similar to subplot(122) nrows_ncols=(2, 2), axes_pad=0.10, label_mode="1", share_all=True, cbar_location="right", cbar_mode="edge", cbar_size="7%", cbar_pad="2%", ) Z, extent = get_demo_image() cmaps = [plt.get_cmap("spring"), plt.get_cmap("winter")] for i in range(4): im = grid[i].imshow(Z, extent=extent, interpolation="nearest", cmap=cmaps[i//2]) if i % 2: grid.cbar_axes[i//2].colorbar(im) for cax in grid.cbar_axes: cax.toggle_label(True) cax.axis[cax.orientation].set_label('Foo') # This affects all axes because we set share_all = True. grid.axes_llc.set_xticks([-2, 0, 2]) grid.axes_llc.set_yticks([-2, 0, 2])
Example #3
Source File: plot_occluded_activations.py From kaggle-dr with MIT License | 5 votes |
def accumulate_patches_into_heatmaps(self, all_test_output, outpath_prefix=''): outpath = "plots/%s_%s.png" % (outpath_prefix, path.splitext(path.basename(self.test_imagepath))[0]) # http://matplotlib.org/examples/axes_grid/demo_axes_grid.html fig = plt.figure() grid = AxesGrid(fig, 143, # similar to subplot(143) nrows_ncols = (1, 1)) orig_img = imread(self.test_imagepath+'.png') grid[0].imshow(orig_img) grid = AxesGrid(fig, 144, # similar to subplot(144) nrows_ncols = (2, 2), axes_pad = 0.15, label_mode = "1", share_all = True, cbar_location="right", cbar_mode="each", cbar_size="7%", cbar_pad="2%", ) for klass in xrange(all_test_output.shape[1]): accumulator = numpy.zeros(self.ds.image_shape[:2]) normalizer = numpy.zeros(self.ds.image_shape[:2]) for n in xrange(self.num_patch_centers): i_start,i_end,j_start,j_end = self.nth_patch(n) accumulator[i_start:i_end, j_start:j_end] += all_test_output[n,klass] normalizer[i_start:i_end, j_start:j_end] += 1 normalized_img = accumulator / normalizer im = grid[klass].imshow(normalized_img, interpolation="nearest", vmin=0, vmax=1) grid.cbar_axes[klass].colorbar(im) grid.axes_llc.set_xticks([]) grid.axes_llc.set_yticks([]) print("Saving figure as: %s" % outpath) plt.savefig(outpath, dpi=600, bbox_inches='tight')
Example #4
Source File: figures.py From kaggle-dr with MIT License | 5 votes |
def plot_pathological_imgs(): fig = plt.figure() grid = AxesGrid(fig, 111, nrows_ncols = (1, 4)) names = ['23050_right.png', '2468_left.png', '15450_left.png', '406_left.png'] imgs = [imread(n) for n in names] [grid[i].imshow(imgs[i]) for i in range(len(imgs))] plt.axis('off') plt.savefig('out.png', dpi=300) # figure of all kappa curves # skips 1 lost result from above, is in diff order
Example #5
Source File: visualization.py From scanobjectnn with MIT License | 5 votes |
def make_segmentation_triplets_for_paper(path, cls='Chair', export=False): image_types = ['/gt/', '/pred/', '/diff/'] output_dir = path + '/triplet_images' if cls == 'all': hdf5_data_dir = os.path.join(BASE_DIR, './hdf5_data') all_obj_cat_file = os.path.join(hdf5_data_dir, 'all_object_categories.txt') fin = open(all_obj_cat_file, 'r') lines = [line.rstrip() for line in fin.readlines()] objnames = [line.split()[0] for line in lines] n_objects = len(objnames) filename = output_dir + '/' + 'all' else: n_objects = 1 filename = output_dir + '/' + cls.title() objnames = [cls.title()] fig = plt.figure() ax = AxesGrid(fig, 111, nrows_ncols=(n_objects, 3), axes_pad=0.0) for i, obj in enumerate(objnames): cls_file_path = path+'/images/' + obj for j, img_type in enumerate(image_types): file_names = [os.path.join(cls_file_path + img_type, f) for f in os.listdir(cls_file_path + img_type)] file_names.sort() img = mpimg.imread(file_names[0]) w = img.shape[1] h = img.shape[0] x0 = int(np.round(w * 0.25)) y0 = int(np.round(h * 0.1)) cropped_img = img[y0:y0+int(0.7*h),x0:x0+int(0.5*w),:] ax[3*i+j].axis('off') ax[3*i+j].imshow(cropped_img) #Visualize and export if not os.path.exists(output_dir): os.mkdir(output_dir) if export: plt.savefig(filename + '.png', format='png', bbox_inches='tight', dpi=600) else: plt.show()
Example #6
Source File: visualize_temp.py From pySDC with BSD 2-Clause "Simplified" License | 4 votes |
def plot_data(path='./data', name='', output='.'): """ Visualization using numpy arrays (written via MPI I/O) and json description Produces one png file per time-step, combine as movie via e.g. > ffmpeg -i data/name_%08d.png name.mp4 Args: path (str): path to data files name (str): name of the simulation (expects data to be in data path) output (str): path to output """ json_files = sorted(glob.glob(f'{path}/{name}_*.json')) data_files = sorted(glob.glob(f'{path}/{name}_*.dat')) for json_file, data_file in zip(json_files, data_files): with open(json_file, 'r') as fp: obj = json.load(fp) index = json_file.split('_')[-1].split('.')[0] print(f'Working on step {index}...') array = np.fromfile(data_file, dtype=obj['datatype']) array = array.reshape(obj['shape'], order='C') fig = plt.figure() grid = AxesGrid(fig, 111, nrows_ncols=(1, 2), axes_pad=0.15, cbar_mode='single', cbar_location='right', cbar_pad=0.15 ) im = grid[0].imshow(array[..., 0], vmin=0, vmax=1) im = grid[1].imshow(array[..., 1], vmin=0, vmax=1) grid[0].set_title(f"Field - Time: {obj['time']:6.4f}") grid[1].set_title(f"Temperature - Time: {obj['time']:6.4f}") grid[1].yaxis.set_visible(False) grid.cbar_axes[0].colorbar(im) plt.savefig(f'{output}/{name}_{index}.png', rasterized=True, bbox_inches='tight') plt.close()