Python matplotlib.pyplot.set_cmap() Examples
The following are 30
code examples of matplotlib.pyplot.set_cmap().
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
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: cellular_automaton.py From cellular_automata with GNU General Public License v2.0 | 6 votes |
def plot_dff(dff, walls, name="DFF", max_value=None, title=""): fig = plt.figure() ax = fig.add_subplot(111) ax.cla() plt.set_cmap('jet') cmap = plt.get_cmap() cmap.set_bad(color='k', alpha=0.8) vect = dff.copy() vect[walls < 0] = np.Inf im = ax.imshow(vect, cmap=cmap, interpolation='nearest', vmin=0, vmax=max_value, extent=[0, dim_y, 0, dim_x]) # lanczos nearest plt.colorbar(im, format='%.1f') #cbar = plt.colorbar() if title: plt.title(title) figure_name = os.path.join('dff', name+'.png') plt.savefig(figure_name, dpi=600) plt.close() logging.info("plot dff. figure: {}.png".format(name))
Example #2
Source File: nav_env.py From hands-detection with MIT License | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #3
Source File: nav_env.py From object_detection_kitti with Apache License 2.0 | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #4
Source File: nav_env.py From DOTA_models with Apache License 2.0 | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #5
Source File: helpers.py From pychorus with MIT License | 6 votes |
def draw_lines(num_samples, sample_rate, lines): """Debugging function to draw detected lines in black""" lines_matrix = np.zeros((num_samples, num_samples)) for line in lines: lines_matrix[line.lag:line.lag + 4, line.start:line.end + 1] = 1 # Import here since this function is only for debugging import librosa.display import matplotlib.pyplot as plt librosa.display.specshow( lines_matrix, y_axis='time', x_axis='time', sr=sample_rate / (N_FFT / 2048)) plt.colorbar() plt.set_cmap("hot_r") plt.show()
Example #6
Source File: nav_env.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #7
Source File: nav_env.py From object_detection_with_tensorflow with MIT License | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #8
Source File: nav_env.py From models with Apache License 2.0 | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #9
Source File: nav_env.py From yolo_v2 with Apache License 2.0 | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #10
Source File: nav_env.py From Gun-Detector with Apache License 2.0 | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #11
Source File: routine.py From sureal with Apache License 2.0 | 6 votes |
def visualize_pc_dataset(dataset_filepath): dataset = import_python_file(dataset_filepath) dataset_reader = PairedCompDatasetReader(dataset) tensor_pvs_pvs_subject = dataset_reader.opinion_score_3darray plt.figure() # plot the rate of winning x, 0 <= x <= 1.0, of one PVS compared against another PVS mtx_pvs_pvs = np.nansum(tensor_pvs_pvs_subject, axis=2) \ / (np.nansum(tensor_pvs_pvs_subject, axis=2) + np.nansum(tensor_pvs_pvs_subject, axis=2).transpose()) plt.imshow(mtx_pvs_pvs, interpolation='nearest') plt.title(r'Paired Comparison Winning Rate') plt.ylabel(r"PVS ($j$)") plt.xlabel(r"PVS ($j'$) [Compared Against]") plt.set_cmap('jet') plt.colorbar() plt.tight_layout()
Example #12
Source File: nav_env.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def _debug_save_map_nodes(self, seed): """Saves traversible space along with nodes generated on the graph. Takes the seed as input.""" img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed)) node_xyt = self.to_actual_xyt_vec(self.task.nodes) plt.set_cmap('jet'); fig, ax = utils.subplot(plt, (1,1), (12,12)) ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.') ax.set_axis_off(); ax.axis('equal'); if self.room_dims is not None: for i, r in enumerate(self.room_dims['dims']*1): min_ = r[:3]*1 max_ = r[3:]*1 xmin, ymin, zmin = min_ xmax, ymax, zmax = max_ ax.plot([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], 'g') ax.imshow(self.traversible, origin='lower'); with fu.fopen(img_path, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
Example #13
Source File: utils_visualization.py From deepwriting with MIT License | 6 votes |
def plot_matrix_and_get_image(plot_data, fig_height=8, fig_width=12, axis_off=False, colormap="jet"): fig = plt.figure() fig.set_figheight(fig_height) fig.set_figwidth(fig_width) plt.matshow(plot_data, fig.number) if fig_height < fig_width: plt.colorbar(orientation="horizontal") else: plt.colorbar(orientation="vertical") plt.set_cmap(colormap) if axis_off: plt.axis('off') img = fig_to_img(fig) plt.close(fig) return img
Example #14
Source File: cellular_automaton.py From cellular_automata with GNU General Public License v2.0 | 6 votes |
def plot_sff2(SFF, walls, i): """ plots a numbered image. Useful for making movies """ print("plot_sff: %.6d"%i) fig = plt.figure() ax = fig.add_subplot(111) ax.cla() plt.set_cmap('jet') cmap = plt.get_cmap() cmap.set_bad(color='k', alpha=0.8) vect = SFF * walls vect[vect < 0] = np.Inf # print (vect) max_value = np.max(SFF) min_value = np.min(SFF) plt.imshow(vect, cmap=cmap, interpolation='nearest', vmin=min_value, vmax=max_value, extent=[0, dim_y, 0, dim_x]) # lanczos nearest plt.colorbar() # print(i) plt.title("%.6d"%i) figure_name = os.path.join('sff', '%.6d.png'%i) plt.savefig(figure_name) plt.close()
Example #15
Source File: cellular_automaton.py From cellular_automata with GNU General Public License v2.0 | 6 votes |
def plot_sff(SFF, walls): fig = plt.figure() ax = fig.add_subplot(111) ax.cla() plt.set_cmap('jet') cmap = plt.get_cmap() cmap.set_bad(color='k', alpha=0.8) vect = SFF.copy() vect[walls < 0] = np.Inf max_value = np.max(SFF) min_value = np.min(SFF) plt.imshow(vect, cmap=cmap, interpolation='nearest', vmin=min_value, vmax=max_value, extent=[0, dim_y, 0, dim_x]) # lanczos nearest plt.colorbar() figure_name = os.path.join('sff', 'SFF.png') plt.savefig(figure_name, dpi=600) plt.close()
Example #16
Source File: dal_ros_aml.py From dal with MIT License | 6 votes |
def init_figure(self): self.init_fig = True if self.args.figure == True:# and self.obj_fig==None: self.obj_fig = plt.figure(figsize=(16,12)) plt.set_cmap('viridis') self.gridspec = gridspec.GridSpec(3,5) self.ax_map = plt.subplot(self.gridspec[0,0]) self.ax_scan = plt.subplot(self.gridspec[1,0]) self.ax_pose = plt.subplot(self.gridspec[2,0]) self.ax_bel = plt.subplot(self.gridspec[0,1]) self.ax_lik = plt.subplot(self.gridspec[1,1]) self.ax_gtl = plt.subplot(self.gridspec[2,1]) self.ax_pbel = plt.subplot(self.gridspec[0,2:4]) self.ax_plik = plt.subplot(self.gridspec[1,2:4]) self.ax_pgtl = plt.subplot(self.gridspec[2,2:4]) self.ax_act = plt.subplot(self.gridspec[0,4]) self.ax_rew = plt.subplot(self.gridspec[1,4]) self.ax_err = plt.subplot(self.gridspec[2,4]) plt.subplots_adjust(hspace = 0.4, wspace=0.4, top=0.95, bottom=0.05)
Example #17
Source File: dal.py From dal with MIT License | 6 votes |
def init_figure(self): self.init_fig = True if self.args.figure == True:# and self.obj_fig==None: self.obj_fig = plt.figure(figsize=(16,12)) plt.set_cmap('viridis') self.gridspec = gridspec.GridSpec(3,5) self.ax_map = plt.subplot(self.gridspec[0,0]) self.ax_scan = plt.subplot(self.gridspec[1,0]) self.ax_pose = plt.subplot(self.gridspec[2,0]) self.ax_bel = plt.subplot(self.gridspec[0,1]) self.ax_lik = plt.subplot(self.gridspec[1,1]) self.ax_gtl = plt.subplot(self.gridspec[2,1]) self.ax_pbel = plt.subplot(self.gridspec[0,2:4]) self.ax_plik = plt.subplot(self.gridspec[1,2:4]) self.ax_pgtl = plt.subplot(self.gridspec[2,2:4]) self.ax_act = plt.subplot(self.gridspec[0,4]) self.ax_rew = plt.subplot(self.gridspec[1,4]) self.ax_err = plt.subplot(self.gridspec[2,4]) plt.subplots_adjust(hspace = 0.4, wspace=0.4, top=0.95, bottom=0.05)
Example #18
Source File: cmp_summary.py From object_detection_with_tensorflow with MIT License | 5 votes |
def _vis_readout_maps(outputs, global_step, output_dir, metric_summary, N): # outputs is [gt_map, pred_map]: if N >= 0: outputs = outputs[:N] N = len(outputs) plt.set_cmap('jet') fig, axes = utils.subplot(plt, (N, outputs[0][0].shape[4]*2), (5,5)) axes = axes.ravel()[::-1].tolist() for i in range(N): gt_map, pred_map = outputs[i] for j in [0]: for k in range(gt_map.shape[4]): # Display something like the midpoint of the trajectory. id = np.int(gt_map.shape[1]/2) ax = axes.pop(); ax.imshow(gt_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('gt_map') ax = axes.pop(); ax.imshow(pred_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('pred_map') file_name = os.path.join(output_dir, 'readout_map_{:d}.png'.format(global_step)) with fu.fopen(file_name, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0) plt.close(fig)
Example #19
Source File: cmp_summary.py From hands-detection with MIT License | 5 votes |
def _vis_readout_maps(outputs, global_step, output_dir, metric_summary, N): # outputs is [gt_map, pred_map]: if N >= 0: outputs = outputs[:N] N = len(outputs) plt.set_cmap('jet') fig, axes = utils.subplot(plt, (N, outputs[0][0].shape[4]*2), (5,5)) axes = axes.ravel()[::-1].tolist() for i in range(N): gt_map, pred_map = outputs[i] for j in [0]: for k in range(gt_map.shape[4]): # Display something like the midpoint of the trajectory. id = np.int(gt_map.shape[1]/2) ax = axes.pop(); ax.imshow(gt_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('gt_map') ax = axes.pop(); ax.imshow(pred_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('pred_map') file_name = os.path.join(output_dir, 'readout_map_{:d}.png'.format(global_step)) with fu.fopen(file_name, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0) plt.close(fig)
Example #20
Source File: parallel_file.py From Fluid2d with GNU General Public License v3.0 | 5 votes |
def gen_anim(self,varname,cax): plt.ion() plt.figure() plt.set_cmap('Spectral') t,z2d = self.read_crop(varname,-1) im=plt.imshow(z2d,vmin=cax[0],vmax=cax[1],extent=self.domain) plt.colorbar() for kt in range(self.nt): t,z2d=self.read_crop(varname,kt) im.set_data(z2d) plt.title('t = %4.2f'%t) #plt.draw() plt.savefig('%s_%02i.png'%(varname,kt))
Example #21
Source File: cmp_summary.py From DOTA_models with Apache License 2.0 | 5 votes |
def _vis_readout_maps(outputs, global_step, output_dir, metric_summary, N): # outputs is [gt_map, pred_map]: if N >= 0: outputs = outputs[:N] N = len(outputs) plt.set_cmap('jet') fig, axes = utils.subplot(plt, (N, outputs[0][0].shape[4]*2), (5,5)) axes = axes.ravel()[::-1].tolist() for i in range(N): gt_map, pred_map = outputs[i] for j in [0]: for k in range(gt_map.shape[4]): # Display something like the midpoint of the trajectory. id = np.int(gt_map.shape[1]/2) ax = axes.pop(); ax.imshow(gt_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('gt_map') ax = axes.pop(); ax.imshow(pred_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('pred_map') file_name = os.path.join(output_dir, 'readout_map_{:d}.png'.format(global_step)) with fu.fopen(file_name, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0) plt.close(fig)
Example #22
Source File: visualizations.py From fitlins with Apache License 2.0 | 5 votes |
def _visualize(self, data, out_name): from matplotlib import pyplot as plt plt.set_cmap('viridis') plot_and_save(out_name, nis.reporting.plot_design_matrix, data)
Example #23
Source File: cmp_summary.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def _vis_readout_maps(outputs, global_step, output_dir, metric_summary, N): # outputs is [gt_map, pred_map]: if N >= 0: outputs = outputs[:N] N = len(outputs) plt.set_cmap('jet') fig, axes = utils.subplot(plt, (N, outputs[0][0].shape[4]*2), (5,5)) axes = axes.ravel()[::-1].tolist() for i in range(N): gt_map, pred_map = outputs[i] for j in [0]: for k in range(gt_map.shape[4]): # Display something like the midpoint of the trajectory. id = np.int(gt_map.shape[1]/2) ax = axes.pop(); ax.imshow(gt_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('gt_map') ax = axes.pop(); ax.imshow(pred_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('pred_map') file_name = os.path.join(output_dir, 'readout_map_{:d}.png'.format(global_step)) with fu.fopen(file_name, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0) plt.close(fig)
Example #24
Source File: cmp_summary.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def _vis_readout_maps(outputs, global_step, output_dir, metric_summary, N): # outputs is [gt_map, pred_map]: if N >= 0: outputs = outputs[:N] N = len(outputs) plt.set_cmap('jet') fig, axes = utils.subplot(plt, (N, outputs[0][0].shape[4]*2), (5,5)) axes = axes.ravel()[::-1].tolist() for i in range(N): gt_map, pred_map = outputs[i] for j in [0]: for k in range(gt_map.shape[4]): # Display something like the midpoint of the trajectory. id = np.int(gt_map.shape[1]/2) ax = axes.pop(); ax.imshow(gt_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('gt_map') ax = axes.pop(); ax.imshow(pred_map[j,id,:,:,k], origin='lower', interpolation='none', vmin=0., vmax=1.) ax.set_axis_off(); if i == 0: ax.set_title('pred_map') file_name = os.path.join(output_dir, 'readout_map_{:d}.png'.format(global_step)) with fu.fopen(file_name, 'w') as f: fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0) plt.close(fig)
Example #25
Source File: visualize.py From gaussian-prototypical-networks with MIT License | 5 votes |
def visualize(images, output = "characters.png", width = 20): images = 1.0 - images N,h,w = np.shape(images) Wi = int(np.floor(np.sqrt(N))) Wi = width Hi = int(np.ceil((1.0*N) / (1.0*Wi))) big = np.zeros((Hi*h,Wi*w)) for yi in range(Hi): for xi in range(Wi): i = yi*Wi + xi if i < N: big[yi*h:(yi+1)*h,xi*w:(xi+1)*w] = images[i,:,:] print(big.shape) plt.axis('off') plt.set_cmap('Greys') plt.imshow(big) plt.savefig(output, bbox_inches='tight', format='png', dpi=1200) plt.show()
Example #26
Source File: mriutils.py From mri-variationalnetwork with MIT License | 5 votes |
def phaseshow(img, title=''): """ Show phase of image. """ if not (img.dtype == np.complex64 or img.dtype == np.complex128): print('img is not complex!') img = np.angle(img) plt.figure() plt.imshow(img, cmap='gray', interpolation='nearest') plt.axis('off') plt.colorbar() plt.title(title) plt.set_cmap('hsv')
Example #27
Source File: simulation.py From pykaldi2 with MIT License | 5 votes |
def imagesc(data, show_color_bar=False, title=None, new_figure=False, colormap='jet'): import matplotlib.pyplot as plt import torch if type(data) == torch.Tensor: data = data.to('cpu').data.numpy() if new_figure: plt.figure() plt.imshow(data, aspect='auto') plt.set_cmap(colormap) if show_color_bar: plt.colorbar() if title is not None: plt.title(title)
Example #28
Source File: similarity_matrix.py From pychorus with MIT License | 5 votes |
def display(self): import librosa.display import matplotlib.pyplot as plt librosa.display.specshow( self.matrix, y_axis='time', x_axis='time', sr=self.sample_rate / (N_FFT / 2048)) plt.colorbar() plt.set_cmap("hot_r") plt.show()
Example #29
Source File: demo.py From Image-Captioning-PyTorch with Apache License 2.0 | 5 votes |
def visualize_att(image_path, seq, alphas, rev_word_map, i, smooth=True): """ Visualizes caption with weights at every word. Adapted from paper authors' repo: https://github.com/kelvinxu/arctic-captions/blob/master/alpha_visualization.ipynb :param image_path: path to image that has been captioned :param seq: caption :param alphas: weights :param rev_word_map: reverse word mapping, i.e. ix2word :param smooth: smooth weights? """ image = Image.open(image_path) image = image.resize([14 * 24, 14 * 24], Image.LANCZOS) words = [rev_word_map[ind] for ind in seq] print(words) for t in range(len(words)): if t > 50: break plt.subplot(np.ceil(len(words) / 5.), 5, t + 1) plt.text(0, 1, '%s' % (words[t]), color='black', backgroundcolor='white', fontsize=12) plt.imshow(image) current_alpha = alphas[t, :] if smooth: alpha = skimage.transform.pyramid_expand(current_alpha.numpy(), upscale=24, sigma=8) else: alpha = skimage.transform.resize(current_alpha.numpy(), [14 * 24, 14 * 24]) if t == 0: plt.imshow(alpha, alpha=0) else: plt.imshow(alpha, alpha=0.8) plt.set_cmap(cm.Greys_r) plt.axis('off') plt.savefig('images/out_{}.jpg'.format(i)) plt.close()
Example #30
Source File: test_utils.py From Automated-Cardiac-Segmentation-and-Disease-Diagnosis with MIT License | 5 votes |
def sitk_show(nda, title=None, margin=0.0, dpi=40): figsize = (1 + margin) * nda.shape[0] / dpi, (1 + margin) * nda.shape[1] / dpi extent = (0, nda.shape[1], nda.shape[0], 0) fig = plt.figure(figsize=figsize, dpi=dpi) ax = fig.add_axes([margin, margin, 1 - 2*margin, 1 - 2*margin]) plt.set_cmap("gray") for k in range(0,nda.shape[2]): print ("printing slice "+str(k)) ax.imshow(np.squeeze(nda[:,:,k]),extent=extent,interpolation=None) plt.draw() plt.pause(0.1) #plt.waitforbuttonpress()