本文整理汇总了Python中matplotlib.pyplot.Rectangle方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.Rectangle方法的具体用法?Python pyplot.Rectangle怎么用?Python pyplot.Rectangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.Rectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hinton
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def hinton(matrix, max_weight=None, ax=None):
"""Draw Hinton diagram for visualizing a weight matrix."""
ax = ax if ax is not None else plt.gca()
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(w) / max_weight)
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()
示例2: show_boxes
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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
示例3: _vis_minibatch
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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()
示例4: vis_detections
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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()
示例5: _vis_minibatch
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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()
示例6: _plot_image
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def _plot_image(self, data, gt_boxes, num_boxes):
import matplotlib.pyplot as plt
X=data.cpu().numpy().copy()
X += cfg.PIXEL_MEANS
X = X.astype(np.uint8)
X = X.squeeze(0)
boxes = gt_boxes.squeeze(0)[:num_boxes.view(-1)[0],:].cpu().numpy().copy()
fig, ax = plt.subplots(figsize=(8,8))
ax.imshow(X[:,:,::-1], aspect='equal')
for i in range(boxes.shape[0]):
bbox = boxes[i, :4]
ax.add_patch(
plt.Rectangle((bbox[0], bbox[1]),
bbox[2]-bbox[0],
bbox[3]-bbox[1], fill=False, linewidth=2.0)
)
#plt.imshow(X[:,:,::-1])
plt.tight_layout()
plt.show()
示例7: vis_detections
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def vis_detections(self , im, dets, image_name ):
cv2.imwrite("./tmp_res/"+str(image_name)+"ori.jpg" , im)
print (im)
size = im.shape[0]
dets = dets*size
"""Draw detected bounding boxes."""
class_name = 'face'
#im = im[:, :, (2, 1, 0)]
fig, ax = plt.subplots(figsize=(12, 12))
ax.imshow(im, aspect='equal')
for i in range(len(dets)):
bbox = dets[i, :4]
ax.add_patch(
plt.Rectangle((bbox[0], bbox[1]),
bbox[2] - bbox[0] + 1,
bbox[3] - bbox[1] + 1, fill=False,
edgecolor='red', linewidth=2.5)
)
plt.axis('off')
plt.tight_layout()
plt.savefig('./tmp_res/'+str(image_name)+".jpg", dpi=fig.dpi)
示例8: vis_detections
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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()
示例9: vis_detections
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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()
示例10: hinton
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def hinton(matrix, max_weight=None, ax=None):
"""Draw Hinton diagram for visualizing a weight matrix."""
ax = ax if ax is not None else plt.gca()
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(w) / max_weight)
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()
return ax
示例11: bbox_to_patch
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def bbox_to_patch(bbox, patch=None):
import matplotlib.pyplot as plt
if bbox is None:
return patch
out_patch = []
for i, bb in enumerate(bbox):
xy = (bb[1], bb[0])
height = bb[2] - bb[0]
width = bb[3] - bb[1]
if patch is None:
out_patch.append(
plt.Rectangle(
xy, width, height, fill=False))
else:
patch[i].set_xy(xy)
patch[i].set_width(width)
patch[i].set_height(height)
out_patch.append(patch[i])
return out_patch
示例12: plot_friction_cone
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def plot_friction_cone(self, color='y', scale=1.0):
success, cone, in_normal = self.friction_cone()
ax = plt.gca(projection='3d')
self.graspable.sdf.scatter() # object
x, y, z = self.graspable.sdf.transform_pt_obj_to_grid(self.point)
nx, ny, nz = self.graspable.sdf.transform_pt_obj_to_grid(in_normal, direction=True)
ax.scatter([x], [y], [z], c=color, s=60) # contact
ax.scatter([x - nx], [y - ny], [z - nz], c=color, s=60) # normal
if success:
ax.scatter(x + scale * cone[0], y + scale * cone[1], z + scale * cone[2], c=color, s=40) # cone
ax.set_xlim3d(0, self.graspable.sdf.dims_[0])
ax.set_ylim3d(0, self.graspable.sdf.dims_[1])
ax.set_zlim3d(0, self.graspable.sdf.dims_[2])
return plt.Rectangle((0, 0), 1, 1, fc=color) # return a proxy for legend
示例13: show_boxes
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
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
示例14: vis_detections
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def vis_detections(im, class_name, dets, thresh=0.5):
"""Draw detected bounding boxes."""
inds = np.where(dets[:, -1] >= thresh)[0]
if len(inds) == 0:
return
im = im[:, :, (2, 1, 0)]
fig, ax = plt.subplots(figsize=(12, 12))
ax.imshow(im, aspect='equal')
for i in inds:
bbox = dets[i, :4]
score = dets[i, -1]
ax.add_patch(
plt.Rectangle((bbox[0], bbox[1]),
bbox[2] - bbox[0],
bbox[3] - bbox[1], fill=False,
edgecolor='red', linewidth=3.5)
)
ax.text(bbox[0], bbox[1] - 2,
'{:s} {:.3f}'.format(class_name, score),
bbox=dict(facecolor='blue', alpha=0.5),
fontsize=14, color='white')
ax.set_title(('{} detections with '
'p({} | box) >= {:.1f}').format(class_name, class_name,
thresh),
fontsize=14)
plt.axis('off')
plt.tight_layout()
plt.draw()
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:33,代码来源:demo.py
示例15: vis_detection
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Rectangle [as 别名]
def vis_detection(im_orig, detections, class_names, thresh=0.7):
"""visualize [cls, conf, x1, y1, x2, y2]"""
import matplotlib.pyplot as plt
import random
plt.imshow(im_orig)
colors = [(random.random(), random.random(), random.random()) for _ in class_names]
for [cls, conf, x1, y1, x2, y2] in detections:
cls = int(cls)
if cls > 0 and conf > thresh:
rect = plt.Rectangle((x1, y1), x2 - x1, y2 - y1,
fill=False, edgecolor=colors[cls], linewidth=3.5)
plt.gca().add_patch(rect)
plt.gca().text(x1, y1 - 2, '{:s} {:.3f}'.format(class_names[cls], conf),
bbox=dict(facecolor=colors[cls], alpha=0.5), fontsize=12, color='white')
plt.show()