Python matplotlib.path.Path.MOVETO Examples

The following are 30 code examples for showing how to use matplotlib.path.Path.MOVETO(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module matplotlib.path.Path , or try the search function .

Example 1
Project: bdd100k   Author: ucbdrive   File: show_labels.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def poly2patch(self, poly2d, closed=False, alpha=1., color=None):
        moves = {'L': Path.LINETO,
                 'C': Path.CURVE4}
        points = [p[:2] for p in poly2d]
        codes = [moves[p[2]] for p in poly2d]
        codes[0] = Path.MOVETO

        if closed:
            points.append(points[0])
            if codes[-1] == 4:
                codes.append(Path.LINETO)
            else:
                codes.append(Path.CLOSEPOLY)

        if color is None:
            color = random_color()

        # print(codes, points)
        return mpatches.PathPatch(
            Path(points, codes),
            facecolor=color if closed else 'none',
            edgecolor=color,  # if not closed else 'none',
            lw=1 if closed else 2 * self.scale, alpha=alpha,
            antialiased=False, snap=True) 
Example 2
Project: bdd100k   Author: ucbdrive   File: show_labels.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def poly2patch(self, vertices, types, closed=False, alpha=1., color=None):
        moves = {'L': Path.LINETO,
                 'C': Path.CURVE4}
        points = [v for v in vertices]
        codes = [moves[t] for t in types]
        codes[0] = Path.MOVETO

        if closed:
            points.append(points[0])
            codes.append(Path.CLOSEPOLY)

        if color is None:
            color = random_color()

        # print(codes, points)
        return mpatches.PathPatch(
            Path(points, codes),
            facecolor=color if closed else 'none',
            edgecolor=color,  # if not closed else 'none',
            lw=1 if closed else 2 * self.scale, alpha=alpha,
            antialiased=False, snap=True) 
Example 3
Project: discopy   Author: oxford-quantum-group   File: drawing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_wire(axis, source, target,
              bend_out=False, bend_in=False, to_tikz=False):
    """
    Draws a wire from source to target using a Bezier curve.
    """
    mid = (target[0], source[1]) if bend_out else (source[0], target[1])
    if to_tikz == "controls":
        cmd = "\\draw {} .. controls {} .. {};\n"
        axis.append(cmd.format(*("({}, {})".format(*point)
                                 for point in [source, mid, target])))
    elif to_tikz:
        out = -90 if not bend_out or source[0] == target[0]\
            else (180 if source[0] > target[0] else 0)
        inp = 90 if not bend_in or source[0] == target[0]\
            else (180 if source[0] < target[0] else 0)
        cmd = "\\draw [out={}, in={}] {{}} to {{}};\n".format(out, inp)
        axis.append(cmd.format(*("({}, {})".format(*point)
                                 for point in [source, target])))
    else:
        path = Path([source, mid, target],
                    [Path.MOVETO, Path.CURVE3, Path.CURVE3])
        axis.add_patch(PathPatch(path, facecolor='none')) 
Example 4
Project: 3d-vehicle-tracking   Author: ucbdrive   File: show_labels.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def poly2patch(self, poly2d, closed=False, alpha=1., color=None):
        moves = {'L': Path.LINETO,
                 'C': Path.CURVE4}
        points = [p[:2] for p in poly2d]
        codes = [moves[p[2]] for p in poly2d]
        codes[0] = Path.MOVETO

        if closed:
            points.append(points[0])
            codes.append(Path.CLOSEPOLY)

        if color is None:
            color = random_color()

        # print(codes, points)
        return mpatches.PathPatch(
            Path(points, codes),
            facecolor=color if closed else 'none',
            edgecolor=color,  # if not closed else 'none',
            lw=1 if closed else 2 * self.scale, alpha=alpha,
            antialiased=False, snap=True) 
Example 5
Project: 3d-vehicle-tracking   Author: ucbdrive   File: show_labels.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def poly2patch(self, vertices, types, closed=False, alpha=1., color=None):
        moves = {'L': Path.LINETO,
                 'C': Path.CURVE4}
        points = [v for v in vertices]
        codes = [moves[t] for t in types]
        codes[0] = Path.MOVETO

        if closed:
            points.append(points[0])
            codes.append(Path.CLOSEPOLY)

        if color is None:
            color = random_color()

        # print(codes, points)
        return mpatches.PathPatch(
            Path(points, codes),
            facecolor=color if closed else 'none',
            edgecolor=color,  # if not closed else 'none',
            lw=1 if closed else 2 * self.scale, alpha=alpha,
            antialiased=False, snap=True) 
Example 6
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB
            x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
            dx, dy = x2 - x1, y2 - y1

            f = self.rad

            cx, cy = x12 + f * dy, y12 - f * dx

            vertices = [(x1, y1),
                        (cx, cy),
                        (x2, y2)]
            codes = [Path.MOVETO,
                     Path.CURVE3,
                     Path.CURVE3]

            return Path(vertices, codes) 
Example 7
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1), (cx, cy), (x2, y2)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            return Path(vertices, codes) 
Example 8
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 6 votes vote down vote up
def _get_bracket(self, x0, y0,
                         cos_t, sin_t, width, length,
                        ):

            # arrow from x0, y0 to x1, y1
            from matplotlib.bezier import get_normal_points
            x1, y1, x2, y2 = get_normal_points(x0, y0, cos_t, sin_t, width)

            dx, dy = length * cos_t, length * sin_t

            vertices_arrow = [(x1 + dx, y1 + dy),
                              (x1, y1),
                              (x2, y2),
                              (x2 + dx, y2 + dy)]
            codes_arrow = [Path.MOVETO,
                           Path.LINETO,
                           Path.LINETO,
                           Path.LINETO]

            return vertices_arrow, codes_arrow 
Example 9
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 6 votes vote down vote up
def transmute(self, path, mutation_size, linewidth):

            x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)

            arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
            b_plus, b_minus = make_wedged_bezier2(
                                    arrow_path,
                                    self.tail_width * mutation_size / 2.,
                                    wm=self.shrink_factor)

            patch_path = [(Path.MOVETO, b_plus[0]),
                          (Path.CURVE3, b_plus[1]),
                          (Path.CURVE3, b_plus[2]),
                          (Path.LINETO, b_minus[2]),
                          (Path.CURVE3, b_minus[1]),
                          (Path.CURVE3, b_minus[0]),
                          (Path.CLOSEPOLY, b_minus[0]),
                          ]
            path = Path([p for c, p in patch_path], [c for c, p in patch_path])

            return path, True 
Example 10
Project: Computable   Author: ktraunmueller   File: inset_locator.py    License: MIT License 6 votes vote down vote up
def get_path(self):
       x0, y0, x1, y1 = self.bbox.extents

       verts = [(x0, y0),
                (x1, y0),
                (x1, y1),
                (x0, y1),
                (x0, y0),
                (0,0)]

       codes = [Path.MOVETO,
                Path.LINETO,
                Path.LINETO,
                Path.LINETO,
                Path.LINETO,
                Path.CLOSEPOLY]

       return Path(verts, codes) 
Example 11
Project: viznet   Author: GiggleLiu   File: shapes.py    License: MIT License 6 votes vote down vote up
def rounded_path(vertices, roundness, close=False):
    '''make rounded path from vertices.'''
    vertices = np.asarray(vertices)
    if roundness == 0:
        vertices = vertices if not close else np.concatenate([vertices, vertices[:1]],axis=0)
        return Path(vertices, codes=[Path.MOVETO]+[Path.LINETO]*(len(vertices)-1))
    if close:
        vertices = np.concatenate([vertices, vertices[:2]], axis=0)

    codes = [Path.MOVETO]
    vertices_new = [vertices[0]]
    if close:
        cur, nex = vertices[:2]
        vertices_new[0] = cur + (nex - cur)/norm(cur-nex)*roundness
    for pre, cur, nex in zip(vertices[:-2], vertices[1:-1], vertices[2:]):
        codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
        dv_pre = (pre - cur)/norm(cur-pre)*roundness
        dv_nex = (nex - cur)/norm(cur-nex)*roundness
        vertices_new.extend([cur+dv_pre,cur,cur+dv_nex])
    if not close:
        codes.append(Path.LINETO)
        vertices_new.append(vertices[-1])
    return Path(vertices_new, codes) 
Example 12
Project: viznet   Author: GiggleLiu   File: brush.py    License: MIT License 6 votes vote down vote up
def rounded_path(vertices, roundness):
    '''make rounded path from vertices.'''
    vertices = np.asarray(vertices)
    if roundness == 0:
        return Path(vertices)

    codes = [Path.MOVETO]
    vertices_new = [vertices[0]]
    for pre, cur, nex in zip(vertices[:-2], vertices[1:-1], vertices[2:]):
        codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
        dv_pre = (pre - cur)/norm(cur-pre)*roundness
        dv_nex = (nex - cur)/norm(cur-nex)*roundness
        vertices_new.extend([cur+dv_pre,cur,cur+dv_nex])
    codes.append(Path.LINETO)
    vertices_new.append(vertices[-1])
    return Path(vertices_new, codes) 
Example 13
Project: matplotlib-4-abaqus   Author: Solid-Mechanics   File: patches.py    License: MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB
            x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
            dx, dy = x2 - x1, y2 - y1

            f = self.rad

            cx, cy = x12 + f * dy, y12 - f * dx

            vertices = [(x1, y1),
                        (cx, cy),
                        (x2, y2)]
            codes = [Path.MOVETO,
                     Path.CURVE3,
                     Path.CURVE3]

            return Path(vertices, codes) 
Example 14
Project: matplotlib-4-abaqus   Author: Solid-Mechanics   File: patches.py    License: MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1), (cx, cy), (x2, y2)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            return Path(vertices, codes) 
Example 15
Project: matplotlib-4-abaqus   Author: Solid-Mechanics   File: patches.py    License: MIT License 6 votes vote down vote up
def _get_bracket(self, x0, y0,
                         cos_t, sin_t, width, length,
                        ):

            # arrow from x0, y0 to x1, y1
            from matplotlib.bezier import get_normal_points
            x1, y1, x2, y2 = get_normal_points(x0, y0, cos_t, sin_t, width)

            dx, dy = length * cos_t, length * sin_t

            vertices_arrow = [(x1 + dx, y1 + dy),
                              (x1, y1),
                              (x2, y2),
                              (x2 + dx, y2 + dy)]
            codes_arrow = [Path.MOVETO,
                           Path.LINETO,
                           Path.LINETO,
                           Path.LINETO]

            return vertices_arrow, codes_arrow 
Example 16
Project: matplotlib-4-abaqus   Author: Solid-Mechanics   File: patches.py    License: MIT License 6 votes vote down vote up
def transmute(self, path, mutation_size, linewidth):

            x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)

            arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
            b_plus, b_minus = make_wedged_bezier2(
                                    arrow_path,
                                    self.tail_width * mutation_size / 2.,
                                    wm=self.shrink_factor)

            patch_path = [(Path.MOVETO, b_plus[0]),
                          (Path.CURVE3, b_plus[1]),
                          (Path.CURVE3, b_plus[2]),
                          (Path.LINETO, b_minus[2]),
                          (Path.CURVE3, b_minus[1]),
                          (Path.CURVE3, b_minus[0]),
                          (Path.CLOSEPOLY, b_minus[0]),
                          ]
            path = Path([p for c, p in patch_path], [c for c, p in patch_path])

            return path, True 
Example 17
Project: matplotlib-4-abaqus   Author: Solid-Mechanics   File: inset_locator.py    License: MIT License 6 votes vote down vote up
def get_path(self):
       x0, y0, x1, y1 = self.bbox.extents

       verts = [(x0, y0),
                (x1, y0),
                (x1, y1),
                (x0, y1),
                (x0, y0),
                (0,0)]

       codes = [Path.MOVETO,
                Path.LINETO,
                Path.LINETO,
                Path.LINETO,
                Path.LINETO,
                Path.CLOSEPOLY]

       return Path(verts, codes) 
Example 18
Project: Grid2Op   Author: rte-france   File: PlotMatplot.py    License: Mozilla Public License 2.0 6 votes vote down vote up
def _draw_powerline_line(self,
                             pos_or_x, pos_or_y,
                             pos_ex_x, pos_ex_y,
                             color, line_style):
        codes = [
            Path.MOVETO,
            Path.LINETO
        ]
        verts = [
            (pos_or_x, pos_or_y),
            (pos_ex_x, pos_ex_y)
        ]
        path = Path(verts, codes)
        patch = patches.PathPatch(path,
                                  color=color,
                                  lw=self._line_color_width,
                                  ls=line_style)
        self.ax.add_patch(patch) 
Example 19
Project: PyMICAPS   Author: flashlxy   File: Map.py    License: GNU General Public License v2.0 5 votes vote down vote up
def DrawShapeFile(area):
        """
        在画布上绘制shp文件
        :param area: 包含shp文件名及线宽和线颜色的一个字典
        :return: 
        """
        try:
            shpfile = area.file
            border_shape = shapefile.Reader(shpfile)
            border = border_shape.shapes()
            for b in border:
                border_points = b.points
                path_data = []
                count = 0
                for cell in border_points:
                    if count == 0:
                        trans = (Path.MOVETO, (cell[0], cell[1]))
                        path_data += [trans]
                        cell_end = cell
                    else:
                        trans = (Path.CURVE4, (cell[0], cell[1]))
                        path_data += [trans]
                trans = (Path.CLOSEPOLY, (cell_end[0], cell_end[1]))
                path_data += [trans]

                codes, verts = list(zip(*path_data))
                path = Path(verts, codes)
                x, y = list(zip(*path.vertices))
                plt.plot(x, y, 'k-', linewidth=area.linewidth, color=area.linecolor)
        except Exception as err:
            print(u'【{0}】{1}-{2}'.format(area['file'], err, datetime.now())) 
Example 20
Project: PyMICAPS   Author: flashlxy   File: maskout.py    License: GNU General Public License v2.0 5 votes vote down vote up
def getPathFromShp(shpfile, region):
    try:
        sf = shapefile.Reader(shpfile)
        vertices = []  # 这块是已经修改的地方
        codes = []  # 这块是已经修改的地方
        paths = []
        for shape_rec in sf.shapeRecords():
            # if shape_rec.record[3] == region:  # 这里需要找到和region匹配的唯一标识符,record[]中必有一项是对应的。
            if region == [100000] or shape_rec.record[4] in region:  # 这块是已经修改的地方
                pts = shape_rec.shape.points
                prt = list(shape_rec.shape.parts) + [len(pts)]
                for i in range(len(prt) - 1):
                    for j in range(prt[i], prt[i + 1]):
                        vertices.append((pts[j][0], pts[j][1]))
                    codes += [Path.MOVETO]
                    codes += [Path.LINETO] * (prt[i + 1] - prt[i] - 2)
                    codes += [Path.CLOSEPOLY]
                path = Path(vertices, codes)
                paths.append(path)
        if paths:
            path = Path.make_compound_path(*paths)
        else:
            path = None
        return path
    except Exception as err:
        print(err)
        return None 
Example 21
Project: Eins   Author: xiongbeer   File: testplot.py    License: MIT License 5 votes vote down vote up
def setPlot(self):
        #绘制跑道
        verts = [
            (self.rX[0] - self.xOffset, self.rY[0] + self.yOffset),
            (self.rX[1] - self.xOffset, self.rY[1] + self.yOffset),
            (self.rX[1] + self.xOffset, self.rY[1] - self.yOffset),
            (self.rX[0] + self.xOffset, self.rY[0] - self.yOffset),
            (self.rX[0] - self.xOffset, self.rY[0] + self.yOffset)
        ]
        codes = [
            Path.MOVETO,
            Path.LINETO,
            Path.LINETO,
            Path.LINETO,
            Path.CLOSEPOLY,
        ]

        path = Path(verts, codes)
        patch = patches.PathPatch(path, facecolor='white', alpha = 0.3)
        self.plotLayer.add_patch(patch)

        #绘制边界
        self.plotLayer.plot([self.rX[0] - self.xOffset, self.rX[1] - self.xOffset], [self.rY[0] + self.yOffset, self.rY[1] + self.yOffset], 'w')
        self.plotLayer.plot([self.rX[0] + self.xOffset, self.rX[1] + self.xOffset], [self.rY[0] - self.yOffset, self.rY[1] - self.yOffset], 'w')

        #绘制车道
        for i in xrange(1,self.lanes+1):
             self.plotLayer.plot() 
Example 22
Project: unmixing   Author: arthur-e   File: visualize.py    License: MIT License 5 votes vote down vote up
def plot_2d_mixing_space(self, features, hold=False):
        '''
        Draws a 2D (triangular) mixing space.
        '''
        codes = [VectorPath.MOVETO, VectorPath.LINETO, VectorPath.LINETO, VectorPath.CLOSEPOLY]
        verts = features[...,0:2].tolist()
        verts.append((0, 0)) # Dummy vertex
        path = VectorPath(verts, codes)
        patch = patches.PathPatch(path, facecolor='black', alpha=0.3, lw=0)
        plt.gca().add_patch(patch)

        if not hold:
            plt.show() 
Example 23
Project: discopy   Author: oxford-quantum-group   File: drawing.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_polygon(axis, *points, to_tikz=False, color='#ffffff'):
    """
    Draws a polygon from a list of points.
    """
    if to_tikz:
        axis.append("\\draw {};\n".format(" -- ".join(
            "({}, {})".format(*x) for x in points + points[:1])))
    else:
        codes = [Path.MOVETO]
        codes += len(points[1:]) * [Path.LINETO] + [Path.CLOSEPOLY]
        path = Path(points + points[:1], codes)
        axis.add_patch(PathPatch(path, facecolor=color)) 
Example 24
Project: jMetalPy   Author: jMetal   File: chord_plot.py    License: MIT License 5 votes vote down vote up
def draw_sector(start_angle=0, end_angle=60, radius=1.0, width=0.2, lw=2, ls='-', ax=None, fc=(1, 0, 0), ec=(0, 0, 0),
                z_order=1):
    if start_angle > end_angle:
        start_angle, end_angle = end_angle, start_angle
    start_angle *= np.pi / 180.
    end_angle *= np.pi / 180.

    # https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%C3%A9zier-curves
    opt = 4. / 3. * np.tan((end_angle - start_angle) / 4.) * radius
    inner = radius * (1 - width)

    vertsPath = [polar_to_cartesian(radius, start_angle),
                 polar_to_cartesian(radius, start_angle) + polar_to_cartesian(opt, start_angle + 0.5 * np.pi),
                 polar_to_cartesian(radius, end_angle) + polar_to_cartesian(opt, end_angle - 0.5 * np.pi),
                 polar_to_cartesian(radius, end_angle),
                 polar_to_cartesian(inner, end_angle),
                 polar_to_cartesian(inner, end_angle) + polar_to_cartesian(opt * (1 - width), end_angle - 0.5 * np.pi),
                 polar_to_cartesian(inner, start_angle) + polar_to_cartesian(opt * (1 - width),
                                                                             start_angle + 0.5 * np.pi),
                 polar_to_cartesian(inner, start_angle),
                 polar_to_cartesian(radius, start_angle)]

    codesPaths = [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.LINETO, Path.CURVE4, Path.CURVE4,
                  Path.CURVE4, Path.CLOSEPOLY]

    if ax is None:
        return vertsPath, codesPaths
    else:
        path = Path(vertsPath, codesPaths)
        patch = patches.PathPatch(path, facecolor=fc, edgecolor=ec, lw=lw, linestyle=ls, zorder=z_order)
        ax.add_patch(patch)
        return (patch) 
Example 25
Project: jMetalPy   Author: jMetal   File: chord_plot.py    License: MIT License 5 votes vote down vote up
def draw_chord(start_angle1=0, end_angle1=60, start_angle2=180, end_angle2=240, radius=1.0, chord_width=0.7, ax=None,
               color=(1, 0, 0), z_order=1):
    if start_angle1 > end_angle1:
        start_angle1, end_angle1 = end_angle1, start_angle1
    if start_angle2 > end_angle2:
        start_angle2, end_angle2 = end_angle2, start_angle2
    start_angle1 *= np.pi / 180.
    end_angle1 *= np.pi / 180.
    start_angle2 *= np.pi / 180.
    end_angle2 *= np.pi / 180.

    optAngle1 = 4. / 3. * np.tan((end_angle1 - start_angle1) / 4.) * radius
    optAngle2 = 4. / 3. * np.tan((end_angle2 - start_angle2) / 4.) * radius
    rchord = radius * (1 - chord_width)

    vertsPath = [polar_to_cartesian(radius, start_angle1),
                 polar_to_cartesian(radius, start_angle1) + polar_to_cartesian(optAngle1, start_angle1 + 0.5 * np.pi),
                 polar_to_cartesian(radius, end_angle1) + polar_to_cartesian(optAngle1, end_angle1 - 0.5 * np.pi),
                 polar_to_cartesian(radius, end_angle1),
                 polar_to_cartesian(rchord, end_angle1), polar_to_cartesian(rchord, start_angle2),
                 polar_to_cartesian(radius, start_angle2),
                 polar_to_cartesian(radius, start_angle2) + polar_to_cartesian(optAngle2, start_angle2 + 0.5 * np.pi),
                 polar_to_cartesian(radius, end_angle2) + polar_to_cartesian(optAngle2, end_angle2 - 0.5 * np.pi),
                 polar_to_cartesian(radius, end_angle2),
                 polar_to_cartesian(rchord, end_angle2), polar_to_cartesian(rchord, start_angle1),
                 polar_to_cartesian(radius, start_angle1)]

    codesPath = [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.CURVE4,
                 Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.CURVE4, Path.CURVE4]

    if ax == None:
        return vertsPath, codesPath
    else:
        path = Path(vertsPath, codesPath)
        patch = patches.PathPatch(path, facecolor=color + (0.5,), edgecolor=color + (0.4,), lw=2, alpha=0.5)
        ax.add_patch(patch)
        return (patch) 
Example 26
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 5 votes vote down vote up
def _recompute_path(self):
        # Inner and outer rings are connected unless the annulus is complete
        if abs((self.theta2 - self.theta1) - 360) <= 1e-12:
            theta1, theta2 = 0, 360
            connector = Path.MOVETO
        else:
            theta1, theta2 = self.theta1, self.theta2
            connector = Path.LINETO

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

        if self.width is not None:
            # Partial annulus needs to draw the outer ring
            # followed by a reversed and scaled inner ring
            v1 = arc.vertices
            v2 = arc.vertices[::-1] * float(self.r - self.width) / self.r
            v = np.vstack([v1, v2, v1[0, :], (0, 0)])
            c = np.hstack([arc.codes, arc.codes, connector, Path.CLOSEPOLY])
            c[len(arc.codes)] = connector
        else:
            # Wedge doesn't need an inner ring
            v = np.vstack([arc.vertices, [(0, 0), arc.vertices[0, :], (0, 0)]])
            c = np.hstack([arc.codes, [connector, connector, Path.CLOSEPOLY]])

        # Shift and scale the wedge to the final location.
        v *= self.r
        v += np.asarray(self.center)
        self._path = Path(v, c) 
Example 27
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 5 votes vote down vote up
def transmute(self, x0, y0, width, height, mutation_size):

            # padding
            pad = mutation_size * self.pad

            # width and height with padding added.
            width, height = width + 2. * pad, \
                            height + 2. * pad,

            # boundary of the padded box
            x0, y0 = x0 - pad, y0 - pad,
            x1, y1 = x0 + width, y0 + height

            cp = [(x0, y0), (x1, y0), (x1, y1), (x0, y1),
                  (x0, y0), (x0, y0)]

            com = [Path.MOVETO,
                   Path.LINETO,
                   Path.LINETO,
                   Path.LINETO,
                   Path.LINETO,
                   Path.CLOSEPOLY]

            path = Path(cp, com)

            return path 
Example 28
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 5 votes vote down vote up
def transmute(self, x0, y0, width, height, mutation_size):

            # padding
            pad = mutation_size * self.pad

            # width and height with padding added.
            width, height = width + 2. * pad, \
                            height + 2. * pad,

            # boundary of the padded box
            x0, y0 = x0 - pad, y0 - pad,
            x1, y1 = x0 + width, y0 + height

            dx = (y1 - y0) / 2.
            dxx = dx * .5
            # adjust x0.  1.4 <- sqrt(2)
            x0 = x0 + pad / 1.4

            cp = [(x0 + dxx, y0), (x1, y0), (x1, y1), (x0 + dxx, y1),
                  (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx),
                  (x0 + dxx, y0 - dxx),  # arrow
                  (x0 + dxx, y0), (x0 + dxx, y0)]

            com = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO,
                   Path.LINETO, Path.LINETO, Path.LINETO,
                   Path.LINETO, Path.CLOSEPOLY]

            path = Path(cp, com)

            return path 
Example 29
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 5 votes vote down vote up
def transmute(self, x0, y0, width, height, mutation_size):

            # padding
            pad = mutation_size * self.pad

            # roudning size. Use a half of the pad if not set.
            if self.rounding_size:
                dr = mutation_size * self.rounding_size
            else:
                dr = pad / 2.

            width, height = width + 2. * pad - 2 * dr, \
                            height + 2. * pad - 2 * dr,

            x0, y0 = x0 - pad + dr, y0 - pad + dr,
            x1, y1 = x0 + width, y0 + height

            cp = [(x0, y0),
                  (x0 + dr, y0 - dr), (x1 - dr, y0 - dr), (x1, y0),
                  (x1 + dr, y0 + dr), (x1 + dr, y1 - dr), (x1, y1),
                  (x1 - dr, y1 + dr), (x0 + dr, y1 + dr), (x0, y1),
                  (x0 - dr, y1 - dr), (x0 - dr, y0 + dr), (x0, y0),
                  (x0, y0)]

            com = [Path.MOVETO,
                   Path.CURVE4, Path.CURVE4, Path.CURVE4,
                   Path.CURVE4, Path.CURVE4, Path.CURVE4,
                   Path.CURVE4, Path.CURVE4, Path.CURVE4,
                   Path.CURVE4, Path.CURVE4, Path.CURVE4,
                   Path.CLOSEPOLY]

            path = Path(cp, com)

            return path 
Example 30
Project: Computable   Author: ktraunmueller   File: patches.py    License: MIT License 5 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1)]
            codes = [Path.MOVETO]

            if self.rad == 0.:
                vertices.append((cx, cy))
                codes.append(Path.LINETO)
            else:
                dx1, dy1 = x1 - cx, y1 - cy
                d1 = (dx1 ** 2 + dy1 ** 2) ** .5
                f1 = self.rad / d1
                dx2, dy2 = x2 - cx, y2 - cy
                d2 = (dx2 ** 2 + dy2 ** 2) ** .5
                f2 = self.rad / d2
                vertices.extend([(cx + dx1 * f1, cy + dy1 * f1),
                                 (cx, cy),
                                 (cx + dx2 * f2, cy + dy2 * f2)])
                codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])

            vertices.append((x2, y2))
            codes.append(Path.LINETO)

            return Path(vertices, codes)