我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用matplotlib.pyplot.waitforbuttonpress()。
def demo_cmd(description="load and align images in a directory", path=None, frame=5, grid=(3, 10), tform=AffineTransform): """load and align images in a directory, animating the process Parameters ---------- see rasl_arg_parser """ parser = rasl_arg_parser(description=description, path=path, frame=frame, grid=grid, tform=tform) args = parser.parse_args() Image = load_images(args.path) if len(Image) < np.prod(args.grid): raise ValueError("Only {} images, specify a smaller --grid than {}"\ .format(len(Image), args.grid)) T = [args.tform().inset(image.shape, args.frame) for image in Image] _ = rasl(Image, T, stop_delta=args.stop, show=args.grid) print("click the image to exit") plt.waitforbuttonpress()
def plot_single(img, title=''): plt.figure() plt.title(title) plt.imshow(img, cmap='gray') plt.waitforbuttonpress()
def plot_multiple(imgs, main_title='', titles=''): num_img = len(imgs) rows = (num_img + 1) / 2 plt.figure() plt.title(main_title) f, axarr = plt.subplots(rows, 2) for i, (img, title) in enumerate(zip(imgs, titles)): axarr[i/2, i%2].imshow(img.astype(np.uint8), cmap='gray') axarr[i/2, i%2].set_title(title) plt.waitforbuttonpress()
def hold_plot(): print('Press any key to exit...') plt.ioff() plt.waitforbuttonpress() plt.close()
def __call__(self, data): """ View the images in data :param tuple data: Data with images at imgcols. :return: unchanged input data :rtype: tuple """ for imgcol, ax in zip(self.imgcols, self.axes): ax.clear() img = np.squeeze(data[imgcol]) # remove single-dim axis, e.g. MxNx1 ax.imshow(img, **self.imargs) ax.figure.canvas.draw() plt.waitforbuttonpress(timeout=self.pause) # or plt.pause(self.pause) return data
def __call__(self, data): """ View the image and its annotation :param tuple data: Data with image at imgcol and annotation at annocol. :return: unchanged input data :rtype: tuple """ img = np.squeeze(data[self.imgcol]) ax = self.axes ax.clear() ax.imshow(img, interpolation=self.interpolation) labelcol = 0.7 for acol in self.annocols: annos = data[acol] if isinstance(annos, (list, tuple)): for anno in iu.annotation2pltpatch(annos, **self._shapeprops()): ax.add_patch(anno) else: fs = ax.get_window_extent().height / 22 p = img.shape[0] / 6 x, y = p / 2, p * labelcol labelcol += 1 ax.text(x, y, str(annos), color=self._textprop('edgecolor'), backgroundcolor=self._textprop('backgroundcolor'), size=fs, family='monospace') ax.figure.canvas.draw() plt.waitforbuttonpress(timeout=self.pause) # or plt.pause(self.pause) return data
def visualize(dom, states_xy, pred_traj): fig, ax = plt.subplots() implot = plt.imshow(dom, cmap="Greys_r") ax.plot(states_xy[:,0], states_xy[:,1], c='b', label='Optimal Path') ax.plot(pred_traj[:,0], pred_traj[:,1], '-X', c='r', label='Predicted Path') ax.plot(states_xy[0,0], states_xy[0,1], '-o', label='Start') ax.plot(states_xy[-1,0], states_xy[-1,1], '-s', label='Goal') legend = ax.legend(loc='upper right', shadow=False) for label in legend.get_texts(): label.set_fontsize('x-small') # the legend text size for label in legend.get_lines(): label.set_linewidth(0.5) # the legend line width plt.draw() plt.waitforbuttonpress(0) plt.close(fig)
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()