當前位置: 首頁>>代碼示例>>Python>>正文


Python patches.Polygon方法代碼示例

本文整理匯總了Python中matplotlib.patches.Polygon方法的典型用法代碼示例。如果您正苦於以下問題:Python patches.Polygon方法的具體用法?Python patches.Polygon怎麽用?Python patches.Polygon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.patches的用法示例。


在下文中一共展示了patches.Polygon方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: display_polygons

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def display_polygons(image, polygons, scores=None, figsize=(16, 16), ax=None, colors=None):
    auto_show = False
    if ax is None:
        _, ax = plt.subplots(1, figsize=figsize)
        auto_show = True
    if colors is None:
        colors = random_colors(len(polygons))

    height, width = image.shape[:2]
    ax.set_ylim(height + 10, -10)
    ax.set_xlim(-10, width + 10)
    ax.axis('off')

    for i, polygon in enumerate(polygons):
        color = colors[i]
        polygon = np.reshape(polygon, (-1, 2))  # 轉為[n,(x,y)]
        patch = patches.Polygon(polygon, facecolor=None, fill=False, color=color)
        ax.add_patch(patch)
        # 多邊形得分
        x1, y1 = polygon[0][:]
        ax.text(x1, y1 - 1, scores[i] if scores is not None else '',
                color='w', size=11, backgroundcolor="none")
    ax.imshow(image.astype(np.uint8))
    if auto_show:
        plt.show() 
開發者ID:yizt,項目名稱:keras-ctpn,代碼行數:27,代碼來源:visualize.py

示例2: box3d_to_lines

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def box3d_to_lines(self, label_id, box3d, calibration, occluded):
        """generate individual bounding box from 3d label"""
        label = Label3d.from_box3d(box3d)
        edges = label.get_edges_with_visibility(calibration)

        box_color = self.get_label_color(label_id)
        alpha = 0.5 if occluded else 0.8

        lines = []
        for edge in edges['dashed']:
            lines.append(mpatches.Polygon(edge, linewidth=2 * self.scale,
                                          linestyle=(0, (2, 2)),
                                          edgecolor=box_color,
                                          facecolor='none', fill=False,
                                          alpha=alpha))
        for edge in edges['solid']:
            lines.append(mpatches.Polygon(edge, linewidth=2 * self.scale,
                                          edgecolor=box_color,
                                          facecolor='none', fill=False,
                                          alpha=alpha))

        return lines 
開發者ID:ucbdrive,項目名稱:bdd100k,代碼行數:24,代碼來源:show_labels.py

示例3: test_plate_detect

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def test_plate_detect():
    print("Testing Plate Detect")

    file = cfg.DATA_DIR / 'demo' / 'test.jpg'

    src = cv2.imread(str(file))
    if cfg.VIS and 0:
        plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
        plt.show()
    results = plate_detect(src)
    if cfg.VIS:
        for res in results:
            print("Plate position: \n", res)
            fig = plt.figure(figsize=(10, 10))
            ax1 = fig.add_subplot(211)
            ax1.imshow(src)
            ax1.add_patch(patches.Polygon(res))
            ax2 = fig.add_subplot(212)
            vis_image = align(src, res)
            ax2.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
            plt.show() 
開發者ID:SunskyF,項目名稱:EasyPR-python,代碼行數:23,代碼來源:plate.py

示例4: _gen_axes_patch

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def _gen_axes_patch(self):
        """
        Returns the patch used to draw the background of the axes.  It
        is also used as the clipping path for any data elements on the
        axes.

        In the standard axes, this is a rectangle, but in other
        projections it may not be.

        .. note::
            Intended to be overridden by new projection types.
        """
        import matplotlib.patches as mpatches
        grid_helper = self.get_grid_helper()
        t = grid_helper.get_boundary()
        return mpatches.Polygon(t) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:floating_axes.py

示例5: single_color

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def single_color(self, **kwargs):
        """
        Creates a single Patch.

        +------------+
        |            |
        |            |
        |     1st    |
        |            |
        |            |
        +------------+

        """
        x1, x2 = self.x, self.x+self.dx
        y1, y2 = self.y, self.y+self.dy
        patch = Polygon([
            [x1, y1], # origin
            [x2, y1], # to bottom right
            [x2, y2], # to top right
            [x1, y2], # to top left
            [x1, y1]])# to origin
        self.patches = [patch] 
開發者ID:wolverton-research-group,項目名稱:periodic-table-plotter,代碼行數:24,代碼來源:plotter.py

示例6: onclick_release

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def onclick_release(self, event):

        if any([x.in_axes(event) for x in self.button_axes]) or self.selected_poly:
            return

        if hasattr(self, 'r_x') and hasattr(self, 'r_y') and None not in [self.r_x, self.r_y, event.xdata, event.ydata]:
            if np.abs(event.xdata - self.r_x)>10 and np.abs(event.ydata - self.r_y)>10: # 10 pixels limit for rectangle creation
                if len(self.points)<4:

                    self.right_click=True
                    self.fig.canvas.mpl_disconnect(self.click_id)
                    self.click_id = None
                    bbox = [np.min([event.xdata, self.r_x]), np.min([event.ydata, self.r_y]), np.max([event.xdata, self.r_x]), np.max([event.ydata, self.r_y])]
                    self.r_x = self.r_y = None

                    self.points = [bbox[0], bbox[1], bbox[0], bbox[3], bbox[2], bbox[3], bbox[2], bbox[1], bbox[0], bbox[1]]
                    self.p = PatchCollection([Polygon(self.points_to_polygon(), closed=True)], facecolor='red', linewidths=0, alpha=0.4)
                    self.ax.add_collection(self.p)
                    self.fig.canvas.draw() 
開發者ID:hanskrupakar,項目名稱:COCO-Style-Dataset-Generator-GUI,代碼行數:21,代碼來源:segment.py

示例7: submit

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def submit(self, event):

        if not self.right_click:
            print ('Right click before submit is a must!!')
        else:

            self.text+=self.radio.value_selected+'\n'+'%.2f'%self.find_poly_area()+'\n'+self.print_points()+'\n\n'
            self.right_click = False
            #print (self.points)

            self.lines, self.circles = [], []
            self.click_id = fig.canvas.mpl_connect('button_press_event', self.onclick)

            self.polys.append(Polygon(self.points_to_polygon(), closed=True, color=np.random.rand(3), alpha=0.4, fill=True))
            if self.submit_p:
                self.submit_p.remove()
            self.submit_p = PatchCollection(self.polys, cmap=matplotlib.cm.jet, alpha=0.4)
            self.ax.add_collection(self.submit_p)
            self.points = [] 
開發者ID:hanskrupakar,項目名稱:COCO-Style-Dataset-Generator-GUI,代碼行數:21,代碼來源:segment.py

示例8: _plot_displacement

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def _plot_displacement(ms):
        if not plot:
            ms.down
            return

        import matplotlib.pyplot as plt
        from matplotlib.patches import Polygon
        fig = plt.figure()
        ax = fig.gca()
        ms.processSources()

        ax.imshow(num.flipud(ms.down), aspect='equal',
                  extent=[0, ms.frame.E.max(), 0, ms.frame.N.max()])
        for src in ms.sources:
            for seg in src.segments:
                p = Polygon(seg.outline(), alpha=.8, fill=False)
                ax.add_artist(p)
            if isinstance(src, OkadaPath):
                nodes = num.array(src.nodes)
                ax.scatter(nodes[:, 0], nodes[:, 1], color='r')
        plt.show()
        fig.clear() 
開發者ID:pyrocko,項目名稱:kite,代碼行數:24,代碼來源:test_source_okada.py

示例9: plot

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def plot(self, mode='image', ax=None, **kwargs):
        """Visualize the box on a matplotlib plot.
        :param mode: How should the box coordinates and angle be interpreted.
            - mode `'image'` corresponds to the situation where x coordinate of the box
              denotes the "row of an image" (ie. the Y coordinate of the plot, arranged downwards)
              and y coordinate of the box corresponds to the "column of an image",
              (ie X coordinate of the plot). In other words, box's x goes downwards and y - rightwards.
            - mode `'math'` corresponds to the "mathematics" situation where box's x and y correspond to the X and Y axes of the plot.
        :param ax: the matplotlib axis to draw on. If unspecified, the current axis is used.
        :param kwargs: arguments passed to the matplotlib's `Polygon` patch object. By default, fill is set to False, color to red and lw to 2.
        :return: The created Polygon object.
        """
        ax = ax or plt.gca()
        poly = self.as_poly()
        if mode == 'image':
            poly = poly[:,[1,0]]
        kwargs.setdefault('fill', False)
        kwargs.setdefault('color', 'r')
        kwargs.setdefault('lw', 2)
        p = patches.Polygon(poly, **kwargs)
        ax.add_patch(p)
        return p 
開發者ID:konstantint,項目名稱:PassportEye,代碼行數:24,代碼來源:geometry.py

示例10: test_path_clipping

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def test_path_clipping():
    fig = plt.figure(figsize=(6.0, 6.2))

    for i, xy in enumerate([
            [(200, 200), (200, 350), (400, 350), (400, 200)],
            [(200, 200), (200, 350), (400, 350), (400, 100)],
            [(200, 100), (200, 350), (400, 350), (400, 100)],
            [(200, 100), (200, 415), (400, 350), (400, 100)],
            [(200, 100), (200, 415), (400, 415), (400, 100)],
            [(200, 415), (400, 415), (400, 100), (200, 100)],
            [(400, 415), (400, 100), (200, 100), (200, 415)]]):
        ax = fig.add_subplot(4, 2, i)
        bbox = [0, 140, 640, 260]
        ax.set_xlim(bbox[0], bbox[0] + bbox[2])
        ax.set_ylim(bbox[1], bbox[1] + bbox[3])
        ax.add_patch(Polygon(
            xy, facecolor='none', edgecolor='red', closed=True)) 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:19,代碼來源:test_path.py

示例11: draw_gene_simple

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def draw_gene_simple(self, ax, bed, ypos, rgb, edgecolor, linewidth):
        """
        draws an interval with direction (if given)
        """

        if bed.strand not in ['+', '-']:
            ax.add_patch(Rectangle((bed.start, ypos),
                         bed.end - bed.start, 1,
                         edgecolor=edgecolor, facecolor=rgb,
                         linewidth=linewidth))
        else:
            vertices = self._draw_arrow(bed.start, bed.end, bed.strand, ypos)
            ax.add_patch(Polygon(vertices, closed=True, fill=True,
                                 edgecolor=edgecolor,
                                 facecolor=rgb,
                                 linewidth=linewidth)) 
開發者ID:deeptools,項目名稱:pyGenomeTracks,代碼行數:18,代碼來源:BedTrack.py

示例12: __init__

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def __init__(self,xcoord,ycoord,**kwargs):
        collections.PatchCollection.__init__(self,[],**kwargs)
        tol = 0.02
        _xdata1 = np.array([xcoord-tol,xcoord,xcoord+tol])
        _ydata1 = np.array([ycoord-tol,ycoord,ycoord-tol])
        _xdata2 = np.array([xcoord-tol,xcoord,xcoord-tol])
        _ydata2 = np.array([ycoord-tol,ycoord,ycoord+tol])
        # Polygons
        p1 = patches.Polygon(zip(_xdata1,_ydata1))
        p1.set_color("r")
        p2 = patches.Polygon(zip(_xdata2,_ydata2))
        #print p1,p2
        #p2.set_color("g")
        # Set data
        self.set_paths((p1,p2))
        self.set_color("k")
        #self.set_marker("-")
        #self.set_mfc('r')
        #self.set_ms(10) 
開發者ID:JorgeDeLosSantos,項目名稱:nusa,代碼行數:21,代碼來源:graph.py

示例13: _measure

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def _measure(self, qxy, cxy, cid, fc=None, ec=None, gt=None, sc=None):
        qx, qy = qxy
        cx, cy = cxy

        # draw gate box
        self._gate(qxy, fc=fc, ec=ec, gt=gt, sc=sc)

        # add measure symbol
        arc = patches.Arc(xy=(qx, qy - 0.15 * HIG), width=WID * 0.7,
                          height=HIG * 0.7, theta1=0, theta2=180, fill=False,
                          ec=self._style.not_gate_lc, linewidth=2, zorder=PORDER_GATE)
        self.ax.add_patch(arc)
        self.ax.plot([qx, qx + 0.35 * WID], [qy - 0.15 * HIG, qy + 0.20 * HIG],
                     color=self._style.not_gate_lc, linewidth=2, zorder=PORDER_GATE)
        # arrow
        self._line(qxy, [cx, cy + 0.35 * WID], lc=self._style.cc, ls=self._style.cline)
        arrowhead = patches.Polygon(((cx - 0.20 * WID, cy + 0.35 * WID),
                                     (cx + 0.20 * WID, cy + 0.35 * WID),
                                     (cx, cy)), fc=self._style.cc, ec=None)
        self.ax.add_artist(arrowhead)
        # target
        if self.cregbundle:
            self.ax.text(cx + .25, cy + .1, str(cid), ha='left', va='bottom',
                         fontsize=0.8 * self._style.fs, color=self._style.tc,
                         clip_on=True, zorder=PORDER_TEXT) 
開發者ID:Qiskit,項目名稱:qiskit-terra,代碼行數:27,代碼來源:matplotlib.py

示例14: plot_polygon

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def plot_polygon(ax, x, **kwargs):
    ax.add_collection(PatchCollection([patches.Polygon(x, True)], **kwargs)) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:4,代碼來源:util.py

示例15: plot_polys

# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import Polygon [as 別名]
def plot_polys(plist,scale=500.0):
        fig, ax = plt.subplots()
        patches = []
        for p in plist:
            poly = Polygon(np.array(p)/scale, True)
            patches.append(poly) 
開發者ID:zaiweizhang,項目名稱:H3DNet,代碼行數:8,代碼來源:box_util.py


注:本文中的matplotlib.patches.Polygon方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。