欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

矩形图

程序员文章站 2022-04-03 16:53:29
...
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
#rectange3个参数,起点坐标,矩形宽度,矩形高度
rect = plt.Rectangle((0.1,0.1),0.5,0.3)
ax.add_patch(rect)
plt.show()

import matplotlib.pyplot as plt
fig = plt.figure()         #创建图
ax = fig.add_subplot(111)  #创建子图
plt.gca().add_patch(plt.Rectangle((0.1,0.1),0.5,0.3))
plt.show()

#roi框是在图像中画出来的,而图像的原点在左上角,但坐标轴的原点在左下角,所以即使Rectangle中参数一模一样,但在图像和坐标轴中画出来的不一样
def _vis_minibatch(im_blob, rois_blob, labels_blob, overlaps):
    """Visualize a mini-batch for debugging."""
    import matplotlib.pyplot as plt
    #print im_blob
    count = 0
    for i in xrange(rois_blob.shape[0]):
        count += 1
        rois = rois_blob[i, :]
        print(rois)
        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]
        #print count
        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()

 

相关标签: 矩形图