コード例 #1
0
ファイル: svg_path.py プロジェクト: hejibo/scpy2
def make_path(d, style):
    items = []
    for c in d.split():
        if c.upper() in codemap:
            items.append(c)
        else:
            x, y = (float(v) for v in c.split(","))
            items.append((x, y))
    codes = []
    vertices = []            
    i = 0
    lx, ly = 0, 0
    last_code = "M"
    while i < len(items):
        code = items[i]
        if not isinstance(code, str):
            code = last_code
        else:
            i += 1
        ucode = code.upper()
        if code.isupper():
            relative = False
        else:
            relative = True
        if ucode in ("M", "L"):
            x, y = items[i]
            i += 1
            if relative:
                x += lx
                y += ly
            codes.append(codemap[ucode])
            vertices.append((x, y))
            lx, ly = x, y
        if ucode == "C":
            if not relative:
                points = items[i:i+3]
            else:
                points = [(_x + lx, _y + ly) for _x, _y in items[i:i+3]]
            codes.extend([codemap[ucode]]*3)
            vertices.extend(points)
            lx, ly = points[-1]
            i += 3
        if ucode == "Z":
            break
        last_code = code
        
    codes[0] = Path.MOVETO
    patch = PathPatch( Path(vertices, codes) )
    patch.set_linewidth( get_number(style.get("stroke-width", "1px") ) )
    fill =  style.get("fill", "none")
    if fill == "none":
        patch.set_fill( None )
    else:
        patch.set_facecolor( fill )
    edge = style.get("stroke", "none")
    patch.set_edgecolor(edge)

    return patch
コード例 #2
0
ファイル: svg_path.py プロジェクト: jtlai0921/PU1908-Python-
def make_path(d, style):
    items = []
    for c in d.split():
        if c.upper() in codemap:
            items.append(c)
        else:
            x, y = (float(v) for v in c.split(","))
            items.append((x, y))
    codes = []
    vertices = []
    i = 0
    lx, ly = 0, 0
    last_code = "M"
    while i < len(items):
        code = items[i]
        if not isinstance(code, str):
            code = last_code
        else:
            i += 1
        ucode = code.upper()
        if code.isupper():
            relative = False
        else:
            relative = True
        if ucode in ("M", "L"):
            x, y = items[i]
            i += 1
            if relative:
                x += lx
                y += ly
            codes.append(codemap[ucode])
            vertices.append((x, y))
            lx, ly = x, y
        if ucode == "C":
            if not relative:
                points = items[i:i + 3]
            else:
                points = [(_x + lx, _y + ly) for _x, _y in items[i:i + 3]]
            codes.extend([codemap[ucode]] * 3)
            vertices.extend(points)
            lx, ly = points[-1]
            i += 3
        if ucode == "Z":
            break
        last_code = code

    codes[0] = Path.MOVETO
    patch = PathPatch(Path(vertices, codes))
    patch.set_linewidth(get_number(style.get("stroke-width", "1px")))
    fill = style.get("fill", "none")
    if fill == "none":
        patch.set_fill(None)
    else:
        patch.set_facecolor(fill)
    edge = style.get("stroke", "none")
    patch.set_edgecolor(edge)

    return patch
コード例 #3
0
def GenWedge(ofs, rx, ry, facecolor='r', label='', alpha=0.3):
    codes, verts = [], []
    amin = 0
    ox, oy = ofs
    if ox == 0 and oy == 0:
        amax = np.pi * 2
        ngoes = 1
    elif ox == 0:
        amax = np.pi
        ngoes = 2
    else:
        amax = np.pi / 2
        ngoes = 4

    phi = np.linspace(amin, amax, 100)

    for g in range(ngoes):
        if g == 0:
            cofs = ofs
        elif g == 1:
            if (ngoes == 2):
                cofs = [0, -ofs[1]]
            else:
                cofs = [-ofs[0], ofs[1]]
        elif g == 2:
            cofs = [-ofs[0], -ofs[1]]
        elif g == 3:
            cofs = [ofs[0], -ofs[1]]

        codes.append(Path.MOVETO)
        if ngoes > 1:
            verts.append(cofs)
        else:
            verts.append([cofs[0] + rx, cofs[1]])

        for p in phi:
            if p == 0:
                codes.append(Path.LINETO)
            else:
                #print dir(Path)
                codes.append(Path.CURVE4)
            verts.append([
                cofs[0] + rx * cos(p + 2 * np.pi / ngoes * g),
                cofs[1] + ry * sin(p + 2 * np.pi / ngoes * g)
            ])
        if (ngoes > 1):
            codes.append(Path.CLOSEPOLY)
            verts.append(ofs)

    w = PathPatch(Path(verts, codes), label=label)
    w.set_alpha(alpha)
    w.set_facecolor(facecolor)
    w.set_linewidth(0.0)
    lhandles.append(w)
    return w
コード例 #4
0
ファイル: bezier_path.py プロジェクト: BrentBaccala/sage
    def _render_on_subplot(self, subplot):
        """
        Render this Bezier path in a subplot.  This is the key function that
        defines how this Bezier path graphics primitive is rendered in matplotlib's
        library.

        TESTS::

            sage: bezier_path([[(0,1),(.5,0),(1,1)]])
            Graphics object consisting of 1 graphics primitive

        ::

            sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]])
            Graphics object consisting of 1 graphics primitive
        """
        from matplotlib.patches import PathPatch
        from matplotlib.path import Path
        from sage.plot.misc import get_matplotlib_linestyle

        options = dict(self.options())

        del options['alpha']
        del options['thickness']
        del options['rgbcolor']
        del options['zorder']
        del options['fill']
        del options['linestyle']

        bpath = Path(self.vertices, self.codes)
        bpatch = PathPatch(bpath, **options)
        options = self.options()
        bpatch.set_linewidth(float(options['thickness']))
        bpatch.set_fill(options['fill'])
        bpatch.set_zorder(options['zorder'])
        a = float(options['alpha'])
        bpatch.set_alpha(a)
        c = to_mpl_color(options['rgbcolor'])
        bpatch.set_edgecolor(c)
        bpatch.set_facecolor(c)
        bpatch.set_linestyle(
            get_matplotlib_linestyle(options['linestyle'], return_type='long'))
        subplot.add_patch(bpatch)
コード例 #5
0
ファイル: bezier_path.py プロジェクト: mcognetta/sage
    def _render_on_subplot(self, subplot):
        """
        Render this Bezier path in a subplot.  This is the key function that
        defines how this Bezier path graphics primitive is rendered in matplotlib's
        library.

        TESTS::

            sage: bezier_path([[(0,1),(.5,0),(1,1)]])
            Graphics object consisting of 1 graphics primitive

        ::

            sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]])
            Graphics object consisting of 1 graphics primitive
        """
        from matplotlib.patches import PathPatch
        from matplotlib.path import Path
        from sage.plot.misc import get_matplotlib_linestyle

        options = dict(self.options())

        del options['alpha']
        del options['thickness']
        del options['rgbcolor']
        del options['zorder']
        del options['fill']
        del options['linestyle']

        bpath = Path(self.vertices, self.codes)
        bpatch = PathPatch(bpath, **options)
        options = self.options()
        bpatch.set_linewidth(float(options['thickness']))
        bpatch.set_fill(options['fill'])
        bpatch.set_zorder(options['zorder'])
        a = float(options['alpha'])
        bpatch.set_alpha(a)
        c = to_mpl_color(options['rgbcolor'])
        bpatch.set_edgecolor(c)
        bpatch.set_facecolor(c)
        bpatch.set_linestyle(get_matplotlib_linestyle(options['linestyle'], return_type='long'))
        subplot.add_patch(bpatch)