当前位置: 首页>>代码示例>>Python>>正文


Python Path.arc方法代码示例

本文整理汇总了Python中matplotlib.path.Path.arc方法的典型用法代码示例。如果您正苦于以下问题:Python Path.arc方法的具体用法?Python Path.arc怎么用?Python Path.arc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.path.Path的用法示例。


在下文中一共展示了Path.arc方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_venn3_region_patch

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
def make_venn3_region_patch(region):
    '''
    Given a venn3 region (as returned from compute_venn3_regions) produces a Patch object,
    depicting the region as a curve.

    >>> centers, radii = solve_venn3_circles((1, 1, 1, 1, 1, 1, 1))
    >>> regions = compute_venn3_regions(centers, radii)
    >>> patches = [make_venn3_region_patch(r) for r in regions]
    '''
    if region is None or len(region[0]) == 0:
        return None
    if region[0] == "CIRCLE":
        return Circle(region[1][0], region[1][1])
    pts, arcs, label_pos = region
    path = [pts[0]]
    for i in range(len(pts)):
        j = (i + 1) % len(pts)
        (center, radius, direction) = arcs[i]
        fromangle = vector_angle_in_degrees(pts[i] - center)
        toangle = vector_angle_in_degrees(pts[j] - center)
        if direction:
            vertices = Path.arc(fromangle, toangle).vertices
        else:
            vertices = Path.arc(toangle, fromangle).vertices
            vertices = vertices[np.arange(len(vertices) - 1, -1, -1)]
        vertices = vertices * radius + center
        path = path + list(vertices[1:])
    codes = [1] + [4] * (len(path) - 1)
    return PathPatch(Path(path, codes))
开发者ID:perphyliu,项目名称:matplotlib-venn,代码行数:31,代码来源:_venn3.py

示例2: test_full_arc

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
def test_full_arc(offset):
    low = offset
    high = 360 + offset

    path = Path.arc(low, high)
    mins = np.min(path.vertices, axis=0)
    maxs = np.max(path.vertices, axis=0)
    np.testing.assert_allclose(mins, -1)
    assert np.allclose(maxs, 1)
开发者ID:DanHickstein,项目名称:matplotlib,代码行数:11,代码来源:test_path.py

示例3: bezier_path

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
    def bezier_path(self):
        """
        Return ``self`` as a Bezier path.

        This is needed to concatenate arcs, in order to
        create hyperbolic polygons.

        EXAMPLES::

            sage: from sage.plot.arc import Arc
            sage: op = {'alpha':1,'thickness':1,'rgbcolor':'blue','zorder':0,
            ....:     'linestyle':'--'}
            sage: Arc(2,3,2.2,2.2,0,2,3,op).bezier_path()
            Graphics object consisting of 1 graphics primitive

            sage: a = arc((0,0),2,1,0,(pi/5,pi/2+pi/12), linestyle="--", color="red")
            sage: b = a[0].bezier_path()
            sage: b[0]
            Bezier path from (1.133..., 0.8237...) to (-0.2655..., 0.9911...)
        """
        from sage.plot.bezier_path import BezierPath
        from sage.plot.graphics import Graphics
        from matplotlib.path import Path
        import numpy as np
        ma = self._matplotlib_arc()
        def theta_stretch(theta, scale):
            theta = np.deg2rad(theta)
            x = np.cos(theta)
            y = np.sin(theta)
            return np.rad2deg(np.arctan2(scale * y, x))
        theta1 = theta_stretch(ma.theta1, ma.width / ma.height)
        theta2 = theta_stretch(ma.theta2, ma.width / ma.height)

        pa = ma
        pa._path = Path.arc(theta1, theta2)
        transform = pa.get_transform().get_matrix()
        cA, cC, cE = transform[0]
        cB, cD, cF = transform[1]
        points = []
        for u in pa._path.vertices:
            x, y = list(u)
            points += [(cA * x + cC * y + cE, cB * x + cD * y + cF)]
        cutlist = [points[0: 4]]
        N = 4
        while N < len(points):
            cutlist += [points[N: N + 3]]
            N += 3
        g = Graphics()
        opt = self.options()
        opt['fill'] = False
        g.add_primitive(BezierPath(cutlist, opt))
        return g
开发者ID:saraedum,项目名称:sage-renamed,代码行数:54,代码来源:arc.py

示例4: __init__

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
    def __init__(self,
                 center=(0,0),
                 r1=0,
                 r2=None,
                 theta1=0,
                 theta2=360,
                 **kwargs
                 ):
        """
        Draw a ring centered at *x*, *y* center with inner radius *r1* and
        outer radius *r2* that sweeps *theta1* to *theta2* (in degrees).

        Valid kwargs are:

        %(Patch)s
        """
        patches.Patch.__init__(self, **kwargs)
        self.center = center
        self.r1, self.r2 = r1,r2
        self.theta1, self.theta2 = theta1,theta2

        # Inner and outer rings are connected unless the annulus is complete
        delta=abs(theta2-theta1)
        if fmod(delta,360)<=1e-12*delta:
            theta1,theta2 = 0,360
            connector = Path.MOVETO
        else:
            connector = Path.LINETO

        # Form the outer ring
        arc = Path.arc(theta1,theta2)

        if r1 > 0:
            # Partial annulus needs to draw the outter ring
            # followed by a reversed and scaled inner ring
            v1 = arc.vertices
            v2 = arc.vertices[::-1]*float(r1)/r2
            v = numpy.vstack([v1,v2,v1[0,:],(0,0)])
            c = numpy.hstack([arc.codes,arc.codes,connector,Path.CLOSEPOLY])
            c[len(arc.codes)]=connector
        else:
            # Wedge doesn't need an inner ring
            v = numpy.vstack([arc.vertices,[(0,0),arc.vertices[0,:],(0,0)]])
            c = numpy.hstack([arc.codes,[connector,connector,Path.CLOSEPOLY]])

        v *= r2
        v += numpy.array(center)
        self._path = Path(v,c)
        self._patch_transform = transforms.IdentityTransform()
开发者ID:liuhuiwisdom,项目名称:WRed,代码行数:51,代码来源:srfe2as2_caxis.py

示例5: draw

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
    def draw(self, renderer):
        """
        Ellipses are normally drawn using an approximation that uses
        eight cubic bezier splines.  The error of this approximation
        is 1.89818e-6, according to this unverified source:

          Lancaster, Don.  Approximating a Circle or an Ellipse Using
          Four Bezier Cubic Splines.

          http://www.tinaja.com/glib/ellipse4.pdf

        There is a use case where very large ellipses must be drawn
        with very high accuracy, and it is too expensive to render the
        entire ellipse with enough segments (either splines or line
        segments).  Therefore, in the case where either radius of the
        ellipse is large enough that the error of the spline
        approximation will be visible (greater than one pixel offset
        from the ideal), a different technique is used.

        In that case, only the visible parts of the ellipse are drawn,
        with each visible arc using a fixed number of spline segments
        (8).  The algorithm proceeds as follows:

          1. The points where the ellipse intersects the axes bounding
          box are located.  (This is done be performing an inverse
          transformation on the axes bbox such that it is relative to
          the unit circle -- this makes the intersection calculation
          much easier than doing rotated ellipse intersection
          directly).

          This uses the "line intersecting a circle" algorithm from:

            Vince, John.  Geometry for Computer Graphics: Formulae,
            Examples & Proofs.  London: Springer-Verlag, 2005.

          2. The angles of each of the intersection points are
          calculated.

          3. Proceeding counterclockwise starting in the positive
          x-direction, each of the visible arc-segments between the
          pairs of vertices are drawn using the bezier arc
          approximation technique implemented in Path.arc().
        """
        if not hasattr(self, 'axes'):
            raise RuntimeError('Arcs can only be used in Axes instances')

        self._recompute_transform()

        # Get the width and height in pixels
        width = self.convert_xunits(self.width)
        height = self.convert_yunits(self.height)
        width, height = self.get_transform().transform_point(
            (width, height))
        inv_error = (1.0 / 1.89818e-6) * 0.5

        if width < inv_error and height < inv_error:
            self._path = Path.arc(self.theta1, self.theta2)
            return Patch.draw(self, renderer)

        def iter_circle_intersect_on_line(x0, y0, x1, y1):
            dx = x1 - x0
            dy = y1 - y0
            dr2 = dx*dx + dy*dy
            D = x0*y1 - x1*y0
            D2 = D*D
            discrim = dr2 - D2

            # Single (tangential) intersection
            if discrim == 0.0:
                x = (D*dy) / dr2
                y = (-D*dx) / dr2
                yield x, y
            elif discrim > 0.0:
                # The definition of "sign" here is different from
                # npy.sign: we never want to get 0.0
                if dy < 0.0:
                    sign_dy = -1.0
                else:
                    sign_dy = 1.0
                sqrt_discrim = npy.sqrt(discrim)
                for sign in (1., -1.):
                    x = (D*dy + sign * sign_dy * dx * sqrt_discrim) / dr2
                    y = (-D*dx + sign * npy.abs(dy) * sqrt_discrim) / dr2
                    yield x, y

        def iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
            epsilon = 1e-9
            if x1 < x0:
                x0e, x1e = x1, x0
            else:
                x0e, x1e = x0, x1
            if y1 < y0:
                y0e, y1e = y1, y0
            else:
                y0e, y1e = y0, y1
            x0e -= epsilon
            y0e -= epsilon
            x1e += epsilon
            y1e += epsilon
            for x, y in iter_circle_intersect_on_line(x0, y0, x1, y1):
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例6: set_theta2

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
 def set_theta2(self, angle):
     self.theta2 = angle
     self._path = Path.arc(self.theta1, self.theta2)
开发者ID:hrashk,项目名称:freefall,代码行数:5,代码来源:freefall.py

示例7: compress_points

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import arc [as 别名]
def compress_points(points):
    bi, bj, bx, by = get_boundary_intersections(points)

    f = bi == bj
    alone_points = points[bi[f]]
    alone_paths = [Path.circle(xy, 0.5) for xy in alone_points]

    edge_lists = [[] for i in range(len(points))]
    n = 0
    for i, j, x, y in zip(bi, bj, bx, by):
        if i != j:
            edge_lists[j].append((i, x, y))
            n += 1

    print("%s points in total: %s edges, %s alone points" %
          (len(points), n, len(alone_points)))

    def patan2(dy, dx):
        """
        Return pseudo-arctangent of dy/dx such that
            patan2(y1, x1) < patan2(y2, x2)
            if and only if
            atan2(y1, x1) < atan2(y2, x2)
        """
        if dy > 0 and dx > 0:
            return (0, dy - dx)
        elif dy > 0 and dx <= 0:
            return (1, -dy - dx)
        elif dy <= 0 and dx > 0:
            return (2, dx - dy)
        else:
            return (3, dx + dy)

    def shift(u, v):
        if v < u:
            return (v[0] + 4, v[1])
        else:
            return v

    def pop_next(i, ox, oy):
        def local_patan2(y, x):
            return patan2(y - points[i, 1], x - points[i, 0])
        u = local_patan2(oy, ox)
        j = min(range(len(edge_lists[i])),
                key=lambda j: shift(u, local_patan2(edge_lists[i][j][2],
                                                    edge_lists[i][j][1])))
        return edge_lists[i].pop(j)

    paths = []
    # print("<path fill=\"black\" fillrule=\"wind\">")
    while n > 0:
        assert sum(len(e) for e in edge_lists) == n
        i = 0
        while not edge_lists[i]:
            i += 1
        start = i
        j, ox, oy = edge_lists[i].pop(0)
        startx, starty = ox, oy
        ux, uy = ox, oy
        # path = ['%s %s m' % (startx, starty)]
        path_vert_lists = [[[startx, starty]]]
        path_code_lists = [[Path.MOVETO]]

        n -= 1
        while j != start:
            i = j
            j, vx, vy = pop_next(i, ux, uy)
            n -= 1
            # path.append(
            #     '%s 0 0 %s %s %s %s %s a' %
            #     (R, R, points[i, 0], points[i, 1], ox, oy))
            ox, oy = points[i]
            theta1 = np.arctan2(uy - oy, ux - ox)
            theta2 = np.arctan2(vy - oy, vx - ox)
            a = Path.arc(theta1 * 180 / np.pi, theta2 * 180 / np.pi)
            a = a.transformed(Affine2D().scale(0.5).translate(ox, oy))
            path_vert_lists.append(a._vertices[1:])
            path_code_lists.append(a._codes[1:])
            ux, uy = vx, vy
        # path.append(
        #     '%s 0 0 %s %s %s %s %s a' %
        #     (R, R, points[j, 0], points[j, 1], startx, starty))
        ox, oy = points[j]
        theta1 = np.arctan2(uy - oy, ux - ox)
        theta2 = np.arctan2(starty - oy, startx - ox)
        a = Path.arc(theta1 * 180 / np.pi, theta2 * 180 / np.pi)
        a = a.transformed(Affine2D().scale(0.5).translate(ox, oy))
        path_vert_lists.append(a._vertices[1:])
        path_code_lists.append(a._codes[1:])
        # print('\n'.join(path))
        paths.append(
            Path(np.concatenate(path_vert_lists),
                 np.concatenate(path_code_lists).astype(Path.code_type)))
    # print("</path>")
    return Path.make_compound_path(*(alone_paths + paths))
开发者ID:Mortal,项目名称:point-union,代码行数:97,代码来源:point_union.py


注:本文中的matplotlib.path.Path.arc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。