我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用matplotlib.pyplot.Rectangle()。
def vis_detections(im, class_name, dets, thresh=0.3): """Visual debugging of detections.""" import matplotlib.pyplot as plt im = im[:, :, (2, 1, 0)] for i in xrange(np.minimum(10, dets.shape[0])): bbox = dets[i, :4] score = dets[i, -1] if score > thresh: plt.cla() plt.imshow(im) plt.gca().add_patch( plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor='g', linewidth=3) ) plt.title('{} {:.3f}'.format(class_name, score)) plt.show()
def saveHintonPlot(self, matrix, num_tests, max_weight=None, ax=None): """Draw Hinton diagram for visualizing a weight matrix.""" fig,ax = plt.subplots(1,1) if not max_weight: max_weight = 2**np.ceil(np.log(np.abs(matrix).max())/np.log(2)) ax.patch.set_facecolor('gray') ax.set_aspect('equal', 'box') ax.xaxis.set_major_locator(plt.NullLocator()) ax.yaxis.set_major_locator(plt.NullLocator()) for (x, y), w in np.ndenumerate(matrix): color = 'white' if w > 0 else 'black' size = np.sqrt(np.abs(0.5*w/num_tests)) # Need to scale so that it is between 0 and 0.5 rect = plt.Rectangle([x - size / 2, y - size / 2], size, size, facecolor=color, edgecolor=color) ax.add_patch(rect) ax.autoscale_view() ax.invert_yaxis() plt.savefig(self.figures_path + self.save_prefix + '-Hinton.eps') plt.close()
def visualize_gt_roidb(imdb, gt_roidb): """ visualize gt roidb :param imdb: the imdb to be visualized :param gt_roidb: [image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped'] :return: None """ import matplotlib.pyplot as plt import skimage.io for i in range(len(gt_roidb)): im_path = imdb.image_path_from_index(imdb.image_set_index[i]) im = skimage.io.imread(im_path) roi_rec = gt_roidb[i] plt.imshow(im) for bbox, gt_class, overlap in zip(roi_rec['boxes'], roi_rec['gt_classes'], roi_rec['gt_overlaps']): box = plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor='g', linewidth=3) plt.gca().add_patch(box) plt.gca().text(bbox[0], bbox[1], imdb.classes[gt_class] + ' {}'.format(overlap[0, gt_class]), color='w') plt.show()
def _vis_minibatch(im_blob, rois_blob, labels_blob, overlaps): """Visualize a mini-batch for debugging.""" import matplotlib.pyplot as plt for i in xrange(rois_blob.shape[0]): rois = rois_blob[i, :] im_ind = rois[0] roi = rois[1:] im = im_blob[im_ind, :, :, :].transpose((1, 2, 0)).copy() im += cfg.PIXEL_MEANS im = im[:, :, (2, 1, 0)] im = im.astype(np.uint8) cls = labels_blob[i] plt.imshow(im) print 'class: ', cls, ' overlap: ', overlaps[i] plt.gca().add_patch( plt.Rectangle((roi[0], roi[1]), roi[2] - roi[0], roi[3] - roi[1], fill=False, edgecolor='r', linewidth=3) ) plt.show()
def add_legend(self, levels=None, loc="lower left"): """ Add a legend to the figure, using the current option settings. """ if levels: legend_bar = [ plt.Rectangle( (0, 0), 1, 1, fc=self.options["color_palette_values"][i], edgecolor="none") for i, _ in enumerate(levels) ] self.g.fig.get_axes()[-1].legend( legend_bar, levels, ncol=self.options.get("label_legend_columns", 1), title=utf8(self.options.get("label_legend", "")), frameon=True, framealpha=0.7, loc=loc).draggable() else: self.g.fig.get_axes()[-1].legend( ncol=self.options.get("label_legend_columns", 1), title=utf8(self.options.get("label_legend", "")), frameon=True, framealpha=0.7, loc=loc).draggable()
def show_boxes(im, dets, classes, scale = 1.0): plt.cla() plt.axis("off") plt.imshow(im) for cls_idx, cls_name in enumerate(classes): cls_dets = dets[cls_idx] for det in cls_dets: bbox = det[:4] * scale color = (rand(), rand(), rand()) rect = plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor=color, linewidth=2.5) plt.gca().add_patch(rect) if cls_dets.shape[1] == 5: score = det[-1] plt.gca().text(bbox[0], bbox[1], '{:s} {:.3f}'.format(cls_name, score), bbox=dict(facecolor=color, alpha=0.5), fontsize=9, color='white') plt.show() return im
def vis_detections(im, class_name, dets, thresh=0.5): """Visual debugging of detections.""" im = im[:, :, (2, 1, 0)] for i in xrange(np.minimum(5, dets.shape[0])): bbox = dets[i, :4] score = dets[i, -1] if score > thresh: plt.cla() plt.imshow(im) plt.gca().add_patch( plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor='g', linewidth=3) ) plt.title('{} {:.3f}'.format(class_name, score)) plt.show()
def Desenha_PV(self,ax,ext,ctm,ccm,pvDiam,thick): #Add PV wall thick=.1 #espessura da parede pvDiam=.8+2.*thick #PV diam pvBLx=(ext-pvDiam/2.) #PV Bottom Left X pvBLy=ccm-thick #PV Bottom Left Y pvH=ctm-ccm+thick #PV Height rect = plt.Rectangle((pvBLx, pvBLy), pvDiam, pvH, facecolor="#aaaaaa",alpha=.70) ax.add_patch(rect) #Add PV pvDiam=.8 #PV diam pvBLx=ext-pvDiam/2. #PV Bottom Left X pvBLy=ccm #PV Bottom Left Y pvH=ctm-ccm-thick/2. #PV Height rect = plt.Rectangle((pvBLx, pvBLy), pvDiam, pvH, facecolor="white") ax.add_patch(rect) #Linha vertical no eixo do PV plt.plot([ext,ext],[ctm,ccm],color='black',linestyle='--')
def _vis_minibatch(im_blob, rois_blob, labels_blob, sublabels_blob): """Visualize a mini-batch for debugging.""" import matplotlib.pyplot as plt for i in xrange(rois_blob.shape[0]): rois = rois_blob[i, :] im_ind = rois[0] roi = rois[2:] im = im_blob[im_ind, :, :, :].transpose((1, 2, 0)).copy() im += cfg.PIXEL_MEANS im = im[:, :, (2, 1, 0)] im = im.astype(np.uint8) cls = labels_blob[i] subcls = sublabels_blob[i] plt.imshow(im) print 'class: ', cls, ' subclass: ', subcls plt.gca().add_patch( plt.Rectangle((roi[0], roi[1]), roi[2] - roi[0], roi[3] - roi[1], fill=False, edgecolor='r', linewidth=3) ) plt.show()
def vis_detections(im, class_name, dets, thresh=0.8): """Visual debugging of detections.""" import matplotlib.pyplot as plt #im = im[:, :, (2, 1, 0)] for i in xrange(np.minimum(10, dets.shape[0])): bbox = dets[i, :4] score = dets[i, -1] if score > thresh: #plt.cla() #plt.imshow(im) plt.gca().add_patch( plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor='g', linewidth=3) ) plt.gca().text(bbox[0], bbox[1] - 2, '{:s} {:.3f}'.format(class_name, score), bbox=dict(facecolor='blue', alpha=0.5), fontsize=14, color='white') plt.title('{} {:.3f}'.format(class_name, score)) #plt.show()
def show_boxes(im, dets, classes, scale = 1.0): plt.cla() plt.axis("off") plt.imshow(im) for cls_idx, cls_name in enumerate(classes): cls_dets = dets[cls_idx] for det in cls_dets: bbox = det[:4] * scale color = (random.random(), random.random(), random.random()) rect = plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor=color, linewidth=2.5) plt.gca().add_patch(rect) if cls_dets.shape[1] == 5: score = det[-1] plt.gca().text(bbox[0], bbox[1], '{:s} {:.3f}'.format(cls_name, score), bbox=dict(facecolor=color, alpha=0.5), fontsize=9, color='white') plt.show() return im