コード例 #1
0
ファイル: path.py プロジェクト: dimensions11/pyx
    def __init__(self, elems, epsilon=None):
        """elems should contain metapost knots or links"""
        if epsilon is None:
            epsilon = _epsilon
        knots = []
        is_closed = True
        for i, elem in enumerate(elems):
            if isinstance(elem, _link):
                elem.set_knots(elems[i - 1], elems[(i + 1) % len(elems)])
            elif isinstance(elem, _knot):
                knots.append(elem)
                if elem.ltype == mp_endpoint or elem.rtype == mp_endpoint:
                    is_closed = False

        # link the knots among each other
        for i in range(len(knots)):
            knots[i - 1].next = knots[i]

        # determine the control points
        mp_make_choices(knots[0], epsilon)

        pathmodule.path.__init__(self)
        # build up the path
        do_moveto = True
        do_lineto = False
        do_curveto = False
        prev = None
        for i, elem in enumerate(elems):
            if isinstance(elem, _link):
                do_moveto = False
                if isinstance(elem, line):
                    do_lineto, do_curveto = True, False
                else:
                    do_lineto, do_curveto = False, True
            elif isinstance(elem, _knot):
                if do_moveto:
                    self.append(pathmodule.moveto_pt(elem.x_pt, elem.y_pt))
                if do_lineto:
                    self.append(pathmodule.lineto_pt(elem.x_pt, elem.y_pt))
                elif do_curveto:
                    self.append(
                        pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt,
                                              elem.lx_pt, elem.ly_pt,
                                              elem.x_pt, elem.y_pt))
                do_moveto = True
                do_lineto = False
                do_curveto = False
                prev = elem

        # close the path if necessary
        if knots[0].ltype == mp_explicit:
            elem = knots[0]
            if do_lineto and is_closed:
                self.append(pathmodule.closepath())
            elif do_curveto:
                self.append(
                    pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt,
                                          elem.ly_pt, elem.x_pt, elem.y_pt))
                if is_closed:
                    self.append(pathmodule.closepath())
コード例 #2
0
class ProteinDomain(Brick):
    _default_color = cmyk.Purple
    _offset = (0, -0.5)
    _path = path(
        moveto(0, 0),
        lineto(1, 0),
        lineto(1, 1),
        lineto(0, 1),
        lineto(0, 0),
        closepath(),
        moveto(1.4, 0),
        lineto(2.4, 0),
        lineto(2.4, 1),
        lineto(1.4, 1),
        lineto(1.4, 0),
        closepath(),
        moveto(2.8, 0),
        lineto(4, 0),
        lineto(4, -0.5),
        lineto(4+sqrt(3), 0.5),
        lineto(4, 1.5),
        lineto(4, 1),
        lineto(2.8, 1),
        lineto(2.8, 0),
        closepath()
    )
コード例 #3
0
ファイル: path.py プロジェクト: asuar078/python_workspace
    def __init__(self, elems, epsilon=None):
        """elems should contain metapost knots or links"""
        if epsilon is None:
            epsilon = _epsilon
        knots = []
        is_closed = True
        for i, elem in enumerate(elems):
            if isinstance(elem, _link):
                elem.set_knots(elems[i-1], elems[(i+1)%len(elems)])
            elif isinstance(elem, _knot):
                knots.append(elem)
                if elem.ltype == mp_endpoint or elem.rtype == mp_endpoint:
                    is_closed = False

        # link the knots among each other
        for i in range(len(knots)):
            knots[i-1].next = knots[i]

        # determine the control points
        mp_make_choices(knots[0], epsilon)

        pathmodule.path.__init__(self)
        # build up the path
        do_moveto = True
        do_lineto = False
        do_curveto = False
        prev = None
        for i, elem in enumerate(elems):
            if isinstance(elem, _link):
                do_moveto = False
                if isinstance(elem, line):
                    do_lineto, do_curveto = True, False
                else:
                    do_lineto, do_curveto = False, True
            elif isinstance(elem, _knot):
                if do_moveto:
                    self.append(pathmodule.moveto_pt(elem.x_pt, elem.y_pt))
                if do_lineto:
                    self.append(pathmodule.lineto_pt(elem.x_pt, elem.y_pt))
                elif do_curveto:
                    self.append(pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt, elem.ly_pt, elem.x_pt, elem.y_pt))
                do_moveto = True
                do_lineto = False
                do_curveto = False
                prev = elem

        # close the path if necessary
        if knots[0].ltype == mp_explicit:
            elem = knots[0]
            if do_lineto and is_closed:
                self.append(pathmodule.closepath())
            elif do_curveto:
                self.append(pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt, elem.ly_pt, elem.x_pt, elem.y_pt))
                if is_closed:
                    self.append(pathmodule.closepath())
コード例 #4
0
ファイル: sunburst.py プロジェクト: mikemwang/sunburst
    def draw_sector(self, end):
        """draw the sector"""
        segment = path.path(
            path.arc(self.xo, self.yo, self.inner_r, self.start_angle,
                     self.end_angle),
            path.arcn(self.xo, self.yo, self.sector_width + self.inner_r,
                      self.end_angle, self.start_angle), path.closepath())
        self.shape_canvas.fill(segment, [self.sector_color])

        # draw a delimiting line between sectors
        line_color = color.gray(0.15)
        if end and (self.end_angle - self.start_angle) < 0.25:
            line_color = color.rgb.red

        r = self.inner_r + self.sector_width
        start_radians = self.start_angle * pi / 180.0
        end_radians = self.end_angle * pi / 180.0
        x0 = self.inner_r * cos(start_radians) + self.xo
        y0 = self.inner_r * sin(start_radians) + self.yo
        x1 = r * cos(start_radians) + self.xo
        y1 = r * sin(start_radians) + self.yo

        self.shape_canvas.stroke(path.line(x0, y0, x1, y1),
                                 [style.linewidth(0.01), line_color])

        x0 = self.inner_r * cos(end_radians) + self.xo
        y0 = self.inner_r * sin(end_radians) + self.yo
        x1 = r * cos(end_radians) + self.xo
        y1 = r * sin(end_radians) + self.yo

        self.shape_canvas.stroke(path.line(x0, y0, x1, y1),
                                 [style.linewidth(0.01), line_color])
コード例 #5
0
def corner(nx, ny, z, facecolor, edgecolor, trans, xdir, ydir):
    if xdir:
        p = path.path(path.moveto(*projector(nx, z, ny)),
                      path.lineto(*projector(nx - 1, z, ny)),
                      path.lineto(*projector(nx - 1, z + 1, ny)),
                      path.lineto(*projector(nx, z + 1, ny)), path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    if ydir:
        p = path.path(path.moveto(*projector(nx, z, ny)),
                      path.lineto(*projector(nx, z, ny + 1)),
                      path.lineto(*projector(nx, z + 1, ny + 1)),
                      path.lineto(*projector(nx, z + 1, ny)), path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    x0, y0 = projector(nx, z, ny)
    x1, y1 = projector(nx, z + 1, ny)
    c.stroke(path.line(x0, y0, x1, y1), [edgecolor])
コード例 #6
0
ファイル: drawer.py プロジェクト: AntipovDen/XdivK
def state(x0, y0, r, c):
    x1 = x0 - r / sqrt(2)
    y1 = y0 + r / sqrt(2)
    x2 = x0 - 3 * r / 4 / sqrt(2)
    y2 = y1 + r / 8
    x3 = x0 - r / 4 / sqrt(2)
    y3 = y1 - r / 8
    x4 = x0 + r / 4 / sqrt(2)
    y4 = y1 + r / 8
    x5 = x0 + 3 * r / 4 / sqrt(2)
    y5 = y1 - r / 8
    x6 = x0 + r / sqrt(2)
    y6 = y1
    delta = r / 40

    c.fill(path.circle(x0, y0, r), [color.cmyk.RoyalBlue])
    c.fill(path.rect(x1 + delta, y0 + delta,
                     r * sqrt(2) - 2 * delta, r), [color.rgb.white])

    inside = path.curve(x1, y1, x2, y2, x3, y3, x0, y1) << \
             path.curve(x0, y1, x4, y4, x5, y5, x6, y6) << \
             path.line(x6, y6, x6, y0) << \
             path.line(x6, y0, x1, y0)
    inside.append(path.closepath())
    c.fill(inside, [color.cmyk.RoyalBlue])
    c.stroke(path.circle(x0, y0, r), [style.linewidth(r / 25)])
コード例 #7
0
    def signature(self, deg_max=6, padded=False, has_border=False):
        """ For a visualization of glyphs, lay out in a 2D grid PNG file. """
        self.scale()
        sig = canvas.canvas([trafo.rotate(90), trafo.mirror(0)])
        scale = 1.5
        if padded or has_border:
            sig_margin = 0.2
            x = (deg_max + 1) * scale + (1.5 * sig_margin)
            border_path = path.path(path.moveto(0, 0), path.lineto(0, x),
                                    path.lineto(x, x), path.lineto(x, 0),
                                    path.closepath())
            if padded:
                border_color = color.cmyk.White
            if has_border:
                border_color = color.cmyk.Gray
            sig.stroke(border_path, [
                border_color,
                trafo.translate(-sig_margin * 2, -sig_margin * 2),
                style.linewidth(.025)
            ])

        for index in self.glist:
            if len(index) > 2:
                c = degree_glyph(index[0], index[1], index[2],
                                 (self.mincount, self.maxcount))
            else:
                c = degree_glyph(index[0], index[1], 1,
                                 (self.mincount, self.maxcount))
            sig.insert(c,
                       [trafo.translate(index[0] * scale, (index[1]) * scale)
                        ])  # text writing requires full latex
        return sig
コード例 #8
0
 def paint(self, canvas, data, axis, axispos):
     if self.breaklinesattrs is not None:
         breaklinesdist_pt = unit.topt(self.breaklinesdist)
         breaklineslength_pt = unit.topt(self.breaklineslength)
         breaklinesextent_pt = (0.5*breaklinesdist_pt*math.fabs(self.cos) +
                                0.5*breaklineslength_pt*math.fabs(self.sin))
         if canvas.extent_pt < breaklinesextent_pt:
             canvas.extent_pt = breaklinesextent_pt
         for v in [data.subaxes[name].vminover for name in data.names[1:]]:
             # use a tangent of the basepath (this is independent of the tickdirection)
             p = axispos.vbasepath(v, None).normpath()
             breakline = p.tangent(0, length=self.breaklineslength)
             widthline = p.tangent(0, length=self.breaklinesdist).transformed(trafomodule.rotate(self.breaklinesangle+90, *breakline.atbegin()))
             # XXX Uiiii
             tocenter = map(lambda x: 0.5*(x[0]-x[1]), zip(breakline.atbegin(), breakline.atend()))
             towidth = map(lambda x: 0.5*(x[0]-x[1]), zip(widthline.atbegin(), widthline.atend()))
             breakline = breakline.transformed(trafomodule.translate(*tocenter).rotated(self.breaklinesangle, *breakline.atbegin()))
             breakline1 = breakline.transformed(trafomodule.translate(*towidth))
             breakline2 = breakline.transformed(trafomodule.translate(-towidth[0], -towidth[1]))
             canvas.fill(path.path(path.moveto_pt(*breakline1.atbegin_pt()),
                               path.lineto_pt(*breakline1.atend_pt()),
                               path.lineto_pt(*breakline2.atend_pt()),
                               path.lineto_pt(*breakline2.atbegin_pt()),
                               path.closepath()), [color.gray.white])
             canvas.stroke(breakline1, self.defaultbreaklinesattrs + self.breaklinesattrs)
             canvas.stroke(breakline2, self.defaultbreaklinesattrs + self.breaklinesattrs)
     _title.paint(self, canvas, data, axis, axispos)
コード例 #9
0
ファイル: features.py プロジェクト: dollodart/dev-cs
 def place(self, x, y):
     x0, y0 = self.coords[0]
     paths = [path.moveto(x + x0, y + y0)]
     for point in self.coords[1:]:
         paths.append(path.lineto(x + point[0], y + point[1]))
     paths.append(path.closepath())
     return (path.path(*paths), self.color, self.stroke_color)
コード例 #10
0
ファイル: painter.py プロジェクト: asuar078/python_workspace
 def paint(self, canvas, data, axis, axispos):
     if self.breaklinesattrs is not None:
         breaklinesdist_pt = unit.topt(self.breaklinesdist)
         breaklineslength_pt = unit.topt(self.breaklineslength)
         breaklinesextent_pt = (0.5*breaklinesdist_pt*math.fabs(self.cos) +
                                0.5*breaklineslength_pt*math.fabs(self.sin))
         if canvas.extent_pt < breaklinesextent_pt:
             canvas.extent_pt = breaklinesextent_pt
         for v in [data.subaxes[name].vminover for name in data.names[1:]]:
             # use a tangent of the basepath (this is independent of the tickdirection)
             p = axispos.vbasepath(v, None).normpath()
             breakline = p.tangent(0, length=self.breaklineslength)
             widthline = p.tangent(0, length=self.breaklinesdist).transformed(trafomodule.rotate(self.breaklinesangle+90, *breakline.atbegin()))
             # XXX Uiiii
             tocenter = map(lambda x: 0.5*(x[0]-x[1]), zip(breakline.atbegin(), breakline.atend()))
             towidth = map(lambda x: 0.5*(x[0]-x[1]), zip(widthline.atbegin(), widthline.atend()))
             breakline = breakline.transformed(trafomodule.translate(*tocenter).rotated(self.breaklinesangle, *breakline.atbegin()))
             breakline1 = breakline.transformed(trafomodule.translate(*towidth))
             breakline2 = breakline.transformed(trafomodule.translate(-towidth[0], -towidth[1]))
             canvas.layer("baseline").fill(path.path(path.moveto_pt(*breakline1.atbegin_pt()),
                                           path.lineto_pt(*breakline1.atend_pt()),
                                           path.lineto_pt(*breakline2.atend_pt()),
                                           path.lineto_pt(*breakline2.atbegin_pt()),
                                           path.closepath()), [color.gray.white])
             canvas.layer("baseline").stroke(breakline1, self.defaultbreaklinesattrs + self.breaklinesattrs)
             canvas.layer("baseline").stroke(breakline2, self.defaultbreaklinesattrs + self.breaklinesattrs)
     _title.paint(self, canvas, data, axis, axispos)
コード例 #11
0
class Promoter(Brick):
    _default_color = cmyk.ForestGreen
    _offset = (0, -0.5)
    _path = path(moveto(0, 0), lineto(1, 0), lineto(1, 0.75), lineto(3, 0.75),
                 lineto(3, 0.25), lineto(3 + sqrt(3) * 0.75, 1.125),
                 lineto(3, 2.0), lineto(3, 1.5), lineto(1, 1.5),
                 curveto(0.5, 1.5, 0.125, 1.5, 0, 1), lineto(0, 0),
                 closepath())
コード例 #12
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
def dopath(ps, extra=[], fill=[], closepath=True, smooth=0.3):
    ps = [path.moveto(*ps[0])]+[path.lineto(*p) for p in ps[1:]]
    if closepath:
        ps.append(path.closepath())
    p = path.path(*ps)
    if fill:
        c.fill(p, [deformer.smoothed(smooth)]+extra+fill)
    c.stroke(p, [deformer.smoothed(smooth)]+extra)
コード例 #13
0
ファイル: decode.py プロジェクト: punkdit/fibonacci
def dopath(ps, extra=[], fill=False, closepath=True):
    ps = [path.moveto(*ps[0])]+[path.lineto(*p) for p in ps[1:]]
    if closepath:
        ps.append(path.closepath())
    p = path.path(*ps)
    if fill:
        c.fill(p, [deformer.smoothed(0.3)]+extra+[color.rgb.white])
    c.stroke(p, [deformer.smoothed(0.3)]+extra)
コード例 #14
0
def server(r, servercolor=color.rgb(0.5, 0.5, 0.8)):
    c = canvas.canvas()
    c.fill(path.circle(0, 0, r), [servercolor, trafo.scale(1, 0.5)])
    h = 2 * r
    p = path.path(path.moveto(-r, 0), path.lineto(-r, -h),
                  path.arc(0, -h, r, 180, 0), path.lineto(r, 0),
                  path.arcn(0, 0, r, 0, 180), path.closepath())
    c.fill(p, [servercolor, trafo.scale(1, 0.5).translated(0, -0.08 * r)])
    return c
コード例 #15
0
def corner(nx, ny, z, facecolor, edgecolor, trans, xdir, ydir):
    if xdir:
        p = path.path(path.moveto(*projector(nx, z, ny)),
                      path.lineto(*projector(nx-1, z, ny)),
                      path.lineto(*projector(nx-1, z+1, ny)),
                      path.lineto(*projector(nx, z+1, ny)),
                      path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    if ydir:
        p = path.path(path.moveto(*projector(nx, z, ny)),
                      path.lineto(*projector(nx, z, ny+1)),
                      path.lineto(*projector(nx, z+1, ny+1)),
                      path.lineto(*projector(nx, z+1, ny)),
                      path.closepath())
        c.fill(p, [facecolor, color.transparency(trans)])
    x0, y0 = projector(nx, z, ny)
    x1, y1 = projector(nx, z+1, ny)
    c.stroke(path.line(x0, y0, x1, y1), [edgecolor])
コード例 #16
0
def polygonal_path(Z, loop=True):
  pa = path.path( path.moveto(Z[0].real, Z[0].imag),
                  path.multilineto_pt(
                     [ ( unit.topt(z.real), unit.topt(z.imag) ) 
                       for z in Z[1:] ] ))
  if loop:
    pa.append(path.closepath())

  return pa
コード例 #17
0
def client(clientcolor=color.rgb(0.8, 0.5, 0.5)):
    c = canvas.canvas()
    r = 0.3
    c.fill(path.circle(0, 0, r), [clientcolor])
    r = 0.5
    p = path.path(path.moveto(-r, 0), path.curveto(-r, r, r, r, r, 0),
                  path.closepath())
    c.fill(p, [clientcolor, trafo.translate(0, -1.3 * r)])
    return c
コード例 #18
0
def read(size, color):
    size = size * 0.25
    cread = canvas.canvas()
    cread.fill(path.circle(0, 0, 0.35), [color, trafo.scale(size)])
    p = path.path(path.moveto(0.8, 0),
                  path.curveto(0.2, 0.5, -0.2, 0.5, -0.8, 0),
                  path.curveto(-0.2, -0.5, 0.2, -0.5, 0.8, 0),
                  path.closepath())
    cread.stroke(p, [color, style.linewidth.thick, trafo.scale(size)])
    return cread
コード例 #19
0
ファイル: visualize.py プロジェクト: alirezakhm/ProAlign
def draw_pie(c, radius, start, end):
    pie = path.path(path.moveto(0, 0), path.arc(0, 0, radius, start, end),
                    path.closepath())

    hue = (start + end) / (360 * 2)
    color = pyx.color.hsb(hue, 0.8, 0.8)

    c.stroke(
        pie,
        [style.linewidth(0.01),
         pyx.color.rgb(1, 1, 1),
         deco.filled([color])])
コード例 #20
0
def write(size, color):
    size = size * 0.3
    cwrite = canvas.canvas()
    p = path.path(path.moveto(-0.2, 0.8), path.lineto(0.2, 0.8),
                  path.lineto(0.2, 0), path.lineto(0, -0.2),
                  path.lineto(-0.2, 0), path.lineto(-0.2, 0.8),
                  path.closepath(), path.moveto(0, 0.8), path.lineto(0, 0.05),
                  path.moveto(-0.2, 0), path.arcn(-0.1, 0, 0.1, 180, 20),
                  path.arcn(0.1, 0, 0.1, 160, 0))
    cwrite.stroke(
        p, [color,
            trafo.scale(size).rotated(-30).translated(0, -0.4 * size)])
    return cwrite
コード例 #21
0
ファイル: drawer.py プロジェクト: AntipovDen/XdivK
def arrow(x0, y0, x1, y1):
    alpha = 0.3
    beta = 0.5
    x2 = x1 + (x1 - x0) * alpha
    y2 = y1 + (y1 - y0) * alpha
    x3 = x2 + (y1 - y0) * beta
    y3 = y2 + (x0 - x1) * beta
    x4 = x2 - (y1 - y0) * beta
    y4 = y2 - (x0 - x1) * beta
    arrow = path.line(x0, y0, x3, y3) << path.line(
        x3, y3, x1, y1) << path.line(x1, y1, x4, y4)
    arrow.append(path.closepath())
    return arrow
コード例 #22
0
 def draw(self):
     p = path.path(path.moveto(*self.corners[0]),
                   path.lineto(*self.corners[1]),
                   path.lineto(*self.corners[2]),
                   path.lineto(*self.corners[3]),
                   path.closepath())
     fillcolor = color.hsb(2/3*(1-(self.counter-1)/(self.nsquares-1)), 0.2, 1)
     self.c.stroke(p, [deco.filled([fillcolor])])
     x, y = 0.5*(self.corners[0]+self.corners[2])
     s = int(np.sum(np.abs(self.corners[1]-self.corners[0])))
     self.c.text(x, y, str(s),
                 [text.halign.center, text.valign.middle,
                  text.size(min(s, 5))])
     self.counter = self.counter+1
コード例 #23
0
ファイル: braid.py プロジェクト: punkdit/surface2015
def dopath(ps, extra=[], fill=[], closepath=False, smooth=0.0):
    if not ps:
        print "dopath: empty"
        return
    ps = [path.moveto(*ps[0])]+[path.lineto(*p) for p in ps[1:]]
    if closepath:
        ps.append(path.closepath())
    p = path.path(*ps)
    extra = list(extra)
    if smooth:
        extra.append(deformer.smoothed(smooth))
    if fill:
        c.fill(p, extra+fill)
    c.stroke(p, extra)
コード例 #24
0
def frontplane(z, nxmax, mymax, facecolor, edgecolor, trans):
    p = path.path(path.moveto(*projector(0, z, 0)),
                  path.lineto(*projector(nxmax, z, 0)),
                  path.lineto(*projector(nxmax, z, nymax)),
                  path.lineto(*projector(0, z, nymax)), path.closepath())
    c.fill(p, [facecolor, color.transparency(trans)])
    c.stroke(p, [edgecolor])
    for nx in range(1, nxmax):
        x0, y0 = projector(nx, z, 0)
        x1, y1 = projector(nx, z, nymax)
        c.stroke(path.line(x0, y0, x1, y1), [edgecolor])
    for ny in range(1, nymax):
        x0, y0 = projector(0, z, ny)
        x1, y1 = projector(nxmax, z, ny)
        c.stroke(path.line(x0, y0, x1, y1), [edgecolor])
コード例 #25
0
 def draw(self):
     p = path.path(path.moveto(*self.corners[0]),
                   path.lineto(*self.corners[1]),
                   path.lineto(*self.corners[2]),
                   path.lineto(*self.corners[3]), path.closepath())
     fillcolor = color.hsb(
         2 / 3 * (1 - (self.counter - 1) / (self.nsquares - 1)), 0.2, 1)
     self.c.stroke(p, [deco.filled([fillcolor])])
     x, y = 0.5 * (self.corners[0] + self.corners[2])
     s = int(np.sum(np.abs(self.corners[1] - self.corners[0])))
     self.c.text(
         x, y, str(s),
         [text.halign.center, text.valign.middle,
          text.size(min(s, 5))])
     self.counter = self.counter + 1
コード例 #26
0
ファイル: visualize.py プロジェクト: alirezakhm/ProAlign
def test_pie(radius, start, end):
    c = canvas.canvas()
    container = path.rect(-(radius + 1), -(radius + 1), 2 * (radius + 1),
                          2 * (radius + 1))

    c.stroke(container, [style.linewidth(0.001), color.rgb.red])

    pie = path.path(path.moveto(0, 0), path.arc(0, 0, radius, start, end),
                    path.closepath())

    c.stroke(pie, [
        style.linewidth(0.1),
        pyx.color.rgb(1, 1, 1),
        deco.filled([color.rgb.red])
    ])
    c.writeSVGfile("figure")
コード例 #27
0
def frontplane(z, nxmax, mymax, facecolor, edgecolor, trans):
    p = path.path(path.moveto(*projector(0, z, 0)),
                  path.lineto(*projector(nxmax, z, 0)),
                  path.lineto(*projector(nxmax, z, nymax)),
                  path.lineto(*projector(0, z, nymax)),
                  path.closepath())
    c.fill(p, [facecolor, color.transparency(trans)])
    c.stroke(p, [edgecolor])
    for nx in range(1, nxmax):
        x0, y0 = projector(nx, z, 0)
        x1, y1 = projector(nx, z, nymax)
        c.stroke(path.line(x0, y0, x1, y1), [edgecolor])
    for ny in range(1, nymax):
        x0, y0 = projector(0, z, ny)
        x1, y1 = projector(nxmax, z, ny)
        c.stroke(path.line(x0, y0, x1, y1), [edgecolor])
コード例 #28
0
ファイル: drawer.py プロジェクト: AntipovDen/XdivK
def draw_drop(x, y, r, c):
    c.fill(path.circle(x, y - 3 * r, r), [color.cmyk.RoyalBlue])
    c.stroke(path.circle(x, y - 3 * r, r))

    triangle = path.line(
        x, y, x + sqrt(8) * r / 3, y - 8 * r / 3) << path.line(
            x + sqrt(8) * r / 3, y - 8 * r / 3, x - sqrt(8) * r / 3,
            y - 8 * r / 3)
    triangle.append(path.closepath())
    c.fill(triangle, [color.cmyk.RoyalBlue])
    c.stroke(
        path.line(x - sqrt(8) * r / 3, y -
                  8 * r / 3, x, y) << path.line(x, y, x + sqrt(8) * r / 3, y -
                                                8 * r / 3))

    c.fill(path.circle(x - 0.5 * r, (y - 3 * r) / 2, 0.2 * r),
           [color.rgb.white, trafo.scale(sx=1, sy=2)])
コード例 #29
0
    def plot(self, canvas, shape="s"):
        """Plot this direction on a pyx canvas.

        The direction will be transformed onto a Lambert equal-area 
        projection and plotted as a square, circle, or triangle
        (shape parameter: s, c, or t).
        """
        (x, y) = self.project()
        if shape == "s":
            canvas.stroke(path.rect(x - 0.1, y - 0.1, 0.2, 0.2))
        elif shape == "t":
            s = 0.15
            canvas.stroke(path.path(path.moveto(x, y + s),
                                    path.rlineto(-0.866 * s, -1.5 * s),
                                    path.rlineto(2 * .866 * s, 0),
                                    path.closepath()))
        elif shape == "c":
            canvas.stroke(path.circle(x, y, 0.1))
コード例 #30
0
def file(c, size=1, xoff=0, yoff=0, attrs=[], title=''):
    w = 3
    h = 2.1
    fold = 0.6
    outline = path.path(path.moveto(0, 0), path.lineto(w, 0),
                        path.lineto(w, h - fold), path.lineto(w - fold, h),
                        path.lineto(0, h), path.closepath())
    foldpath = path.path(path.moveto(w - fold, h),
                         path.lineto(w - fold, h - fold),
                         path.lineto(w, h - fold))
    c1 = canvas.canvas()
    c1.stroke(outline, attrs)
    d = deformer.smoothed(0.2)
    c1.stroke(d.deform(foldpath), attrs)
    c1.stroke(path.rect(0.1 * w, 0.3 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.45 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.6 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.75 * h, 0.6 * w, 0.1 * h))
    c1.text(0.1, 0.1, r'\sffamily ' + title, [trafo.scale(0.7)])
    myattrs = [trafo.translate(xoff, yoff), trafo.scale(size)]
    myattrs.extend(attrs)
    c.insert(c1, myattrs)
コード例 #31
0
def interpolated_path(Z, shape=1.0, loop=True):
  shape /= 6.0

  I = range(0, len(Z)-2)
  if loop:
    I += [-1]

  segments = [ ( Z[i] + (Z[i+1]-Z[i-1])*shape,
                 Z[i+1] - (Z[i+2]-Z[i])*shape,
                 Z[i+1] )  
               for i in I ]
  
  pa = path.path( path.moveto(Z[0].real, Z[0].imag),
                  path.multicurveto_pt(
                    [ (unit.topt(W[0].real), unit.topt(W[0].imag),
                       unit.topt(W[1].real), unit.topt(W[1].imag),
                       unit.topt(W[2].real), unit.topt(W[2].imag) ) 
                      for W in segments ]))
  if loop:
    pa.append(path.closepath())

  return pa
コード例 #32
0
 def zvgridpath(self, vz):
     return path.path(path.moveto_pt(*self.vpos_pt(0, 0, vz)),
                      path.lineto_pt(*self.vpos_pt(1, 0, vz)),
                      path.lineto_pt(*self.vpos_pt(1, 1, vz)),
                      path.lineto_pt(*self.vpos_pt(0, 1, vz)),
                      path.closepath())
コード例 #33
0
 def yvgridpath(self, vy):
     return path.path(path.moveto_pt(*self.vpos_pt(0, vy, 0)),
                      path.lineto_pt(*self.vpos_pt(1, vy, 0)),
                      path.lineto_pt(*self.vpos_pt(1, vy, 1)),
                      path.lineto_pt(*self.vpos_pt(0, vy, 1)),
                      path.closepath())
コード例 #34
0
 def xvgridpath(self, vx):
     return path.path(path.moveto_pt(*self.vpos_pt(vx, 0, 0)),
                      path.lineto_pt(*self.vpos_pt(vx, 1, 0)),
                      path.lineto_pt(*self.vpos_pt(vx, 1, 1)),
                      path.lineto_pt(*self.vpos_pt(vx, 0, 1)),
                      path.closepath())
コード例 #35
0
def plot_memory(data, width, height):
    plot_width = width - 4.0
    plot_height = height - 0.8
    left_width = plot_width * 0.6
    right_width = plot_width * 0.2
    prob = data['HiFive-Probability']['3']
    norm = data['HiCNorm']['3']
    prob_min = prob - right_width * 2.2e4 / left_width * 0.7
    prob_max = prob + right_width * 2.2e4 / left_width * 0.3
    norm_min = norm - right_width * 2.2e4 / left_width * 0.6
    norm_max = norm + right_width * 2.2e4 / left_width * 0.4
    c1 = canvas.canvas()
    g1 = graph.graphxy(width=left_width, height=plot_height,
                      y=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)),
                      x=graph.axis.lin(painter=painter, texter=graph.axis.texter.exponential(mantissaexp=r"{{%s}e%s}", nomantissaexp=r"{e%s}"), min=0, max=2.2e4),
                      x2=graph.axis.lin(parter=None, min=0, max=1),
                      y2=graph.axis.lin(painter=None, min=0, max=1))
    c1.insert(g1, [trafo.translate(0, 0)])
    g2 = graph.graphxy(width=right_width, height=plot_height,
                      y=graph.axis.lin(painter=None, min=0, max=1),
                      x=graph.axis.lin(painter=painter, texter=graph.axis.texter.exponential(mantissaexp=r"{{%s}e%s}", nomantissaexp=r"{e%s}"), min=prob_min, max=prob_max),
                      x2=graph.axis.lin(parter=None, min=0, max=1),
                      y2=graph.axis.lin(painter=None, min=0, max=1))
    c1.insert(g2, [trafo.translate(left_width, 0)])
    g3 = graph.graphxy(width=right_width, height=plot_height,
                      y=graph.axis.lin(painter=None, min=0, max=1),
                      x=graph.axis.lin(painter=painter, texter=graph.axis.texter.exponential(mantissaexp=r"{{%s}e%s}", nomantissaexp=r"{e%s}"), parter=graph.axis.parter.linear(tickdists=[5000]), min=norm_min, max=norm_max),
                      x2=graph.axis.lin(parter=None, min=0, max=1),
                      y2=graph.axis.lin(parter=None, min=0, max=1))
    c1.insert(g3, [trafo.translate(left_width + right_width, 0)])
    split = canvas.canvas()
    split.fill(path.path(path.moveto(-0.15, -0.2), path.lineto(0.05, 0.2), path.lineto(.15, 0.2),
               path.lineto(-0.05, -0.2), path.closepath()), [color.cmyk.White])
    split.stroke(path.line(-0.15, -0.2, 0.05, 0.2))
    split.stroke(path.line(-0.05, -0.2, 0.15, 0.2))
    c1.insert(split, [trafo.translate(left_width, 0)])
    c1.insert(split, [trafo.translate(left_width, plot_height)])
    c1.insert(split, [trafo.translate(left_width + right_width, 0)])
    c1.insert(split, [trafo.translate(left_width + right_width, plot_height)])
    methods = ['HiCLib', 'HiCPipe', 'HiCNorm', 'HiFive-Probability', 'HiFive-Binning', 'HiFive-Express',
               'HiFive-ExpressKR', 'HiFive-ExpressKR w/distance']
    hstep = plot_height / len(methods)
    substep = hstep / 6.0
    scale = left_width / 2.2e4
    for i, meth in enumerate(methods[::-1]):
        for j in range(5):
            if str(j) not in data[meth]:
                continue
            if meth not in ['HiCNorm', 'HiFive-Probability'] or j != 3:
                c1.fill(path.rect(0, hstep * i + (4.5 - j) * substep, data[meth][str(j)] * scale, substep),
                       [step_colors[j]])
            elif meth == 'HiCNorm':
                c1.fill(path.rect(0, hstep * i + (4.5 - j) * substep, left_width + right_width * 1.7, substep),
                       [step_colors[j]])
                c1.insert(split, [trafo.translate(left_width, hstep * i + (5 - j) * substep)])
                c1.insert(split, [trafo.translate(left_width + right_width, hstep * i + (5 - j) * substep)])
            else:
                c1.fill(path.rect(0, hstep * i + (4.5 - j) * substep, left_width + right_width * 0.6, substep),
                       [step_colors[j]])
                c1.insert(split, [trafo.translate(left_width, hstep * i + (5 - j) * substep)])
    c = canvas.canvas()
    c.insert(c1, [trafo.translate(4.0, 0.8)])
    for i, meth in enumerate(methods):
        c.text(3.9, height - plot_height / len(methods) * (i + 0.5), meth,
               [text.halign.right, text.valign.middle, text.size(-2)])
    c.text(4.0 + plot_width / 2, 0, "Maximum RAM usage (resident set size, Mbytes)",
           [text.halign.center, text.valign.bottom, text.size(-2)])
    return c
コード例 #36
0
ファイル: make_icons.py プロジェクト: mitcho/clld
def polygon(*points):  # pragma: no cover
    args = []
    for i, point in enumerate(points):
        args.append(path.moveto(*point) if i == 0 else path.lineto(*point))
    args.append(path.closepath())
    return path.path(*args)
コード例 #37
0
ファイル: fresnel.py プロジェクト: gertingold/feynman-intro
axislen = 3

text.set(engine=text.LatexEngine)
text.preamble(r'''\usepackage[sfdefault,scaled=.85]{FiraSans}
                  \usepackage{newtxsf}
                  \usepackage{nicefrac}''')
unit.set(vscale=1.2, wscale=1.3, xscale=1.3)
c = canvas.canvas()
c.stroke(path.line(-0.2*axislen, 0, axislen, 0), [deco.earrow])
c.text(axislen+0.1, 0, 'Re($x$)', [text.valign.middle])
c.stroke(path.line(0, -0.2*axislen, 0, axislen), [deco.earrow])
c.text(0.2, axislen, 'Im($x$)', [text.valign.top])
r = 0.85*axislen
p = path.path(path.moveto(0, 0),
              path.lineto(r, 0),
              path.arc(0, 0, r, 0, 45),
              path.lineto(0, 0),
              path.closepath())
pathcolor = color.rgb(0.2, 0, 0.8)
c.stroke(p, [style.linewidth.thick, style.linejoin.round, pathcolor])
c.stroke(path.line(0, 0, 0.53*axislen, 0), [deco.earrow, pathcolor])
c.stroke(path.path(path.arc(0, 0, r, 0, 23)), [deco.earrow, pathcolor])
c.stroke(path.path(path.moveto(r/sqrt(2), r/sqrt(2)),
                   path.lineto(0.48*r/sqrt(2), 0.48*r/sqrt(2))),
         [deco.earrow, pathcolor])
c.text(0.33, 0.11, r'\footnotesize$\nicefrac{\pi}{4}$', [pathcolor])
c.stroke(path.path(path.arc(0, 0, 0.82, 0, 45)),
         [style.linewidth.thin, pathcolor])

c.writePDFfile()
コード例 #38
0
ファイル: graph.py プロジェクト: asuar078/python_workspace
 def xvgridpath(self, vx):
     return path.path(path.moveto_pt(*self.vpos_pt(vx, 0, 0)),
                      path.lineto_pt(*self.vpos_pt(vx, 1, 0)),
                      path.lineto_pt(*self.vpos_pt(vx, 1, 1)),
                      path.lineto_pt(*self.vpos_pt(vx, 0, 1)),
                      path.closepath())
コード例 #39
0
ファイル: Segmenter.py プロジェクト: thereddylab/pyLAD
    def plot_scores(self,
                    fname,
                    binsize=10000,
                    show_lads=False,
                    show_dips=False,
                    show_means=False,
                    show_partitions=False):
        """Plot a PDF of score data with optional indicators of partitions, "
        partition means, LADs, and DIPs."""
        # Make sure that the PYX module is available
        try:
            from pyx import canvas, path, document, color, text, style
        except ImportError:
            self.logger.warn("The package pyx must be installed to plot data")
            return None
        # Make sure desired data is present
        if self.focus != 'binned':
            if (self.data is None or numpy.nanmin(self.data['score']) == 0):
                self.logger.warn("Requested data is not available for "
                                 "plotting")
                return None
        elif (self.binned is None or numpy.nanmin(self.binned['score']) == 0):
            self.logger.warn("Requested binned data is not available for "
                             "plotting")
            return None
        self.logger.info("Plotting data")
        # Determine which data to use
        if self.focus == 'binned':
            data = self.binned
            chr_indices = self.bin_indices
        else:
            data = self.data
            chr_indices = self.chr_indices
        # Plot each chromosome on its own page
        pages = []
        for i in range(self.chroms.shape[0]):
            valid = numpy.where(
                numpy.logical_not(
                    numpy.isnan(
                        data['score'][chr_indices[i]:chr_indices[i + 1]])))[0]
            valid += chr_indices[i]
            # Skip chromosomes without valid data
            if valid.shape[0] == 0:
                continue
            mids = (data['coords'][valid, 0] + data['coords'][valid, 1]) // 2
            if binsize > 0:
                # Bin data to the resolution requested
                start = (mids[0] // binsize) * binsize
                stop = (mids[-1] // binsize + 1) * binsize
                indices = (mids - start) // binsize
                counts = numpy.bincount(indices)
                Ys = numpy.bincount(
                    indices, weights=data['score'][valid]) / numpy.maximum(
                        1, counts)
                mids = (start + numpy.arange(
                    (stop - start) // binsize) * binsize + binsize / 2)
                valid = numpy.where(counts > 0)[0]
                Ys = Ys[valid]
                mids = mids[valid]
                coords = numpy.zeros((Ys.shape[0], 2), dtype=numpy.float64)
                coords[:, 0] = start + valid * binsize
                coords[:, 1] = start + valid * binsize + binsize
            else:
                Ys = data['score'][valid]
                start = data['coords'][valid, 0]
                stop = data['coords'][valid[-1], 1]
                coords = data['coords'][valid, :].astype(numpy.float64)
            c = canvas.canvas()
            width = (stop - start) / 5000000.
            height = 5.
            maxscore = numpy.amax(numpy.abs(Ys))
            if show_means and self.partitions is not None:
                where = numpy.where(self.partitions['chr'] == i)[0]
                maxscore = max(
                    maxscore,
                    numpy.amax(numpy.abs(self.partitions['score'][where])))
            Ys /= maxscore
            Ys *= height * 0.5
            Xs = (mids - start) / float(stop - start) * width
            coords -= start
            coords /= (stop - start)
            coords *= width
            lpath = path.path(path.moveto(0, 0))
            for j in range(valid.shape[0]):
                if j == 0 or valid[j] - valid[j - 1] > 1:
                    lpath.append(path.lineto(coords[j, 0], 0))
                lpath.append(path.lineto(Xs[j], Ys[j]))
                if j == Xs.shape[0] - 1 or valid[j + 1] - valid[j] > 1:
                    lpath.append(path.lineto(coords[j, 1], 0))
            lpath.append(path.lineto(width, 0))
            lpath.append(path.closepath())

            # add lads if requests and already determined
            if show_lads and self.LADs is not None:
                where = numpy.where(self.LADs['chr'] == i)[0]
                if where.shape[0] == 0:
                    continue
                for j in where:
                    X0 = ((self.LADs['coords'][j, 0] - start) /
                          float(stop - start) * width)
                    X1 = ((self.LADs['coords'][j, 1] - start) /
                          float(stop - start) * width)
                    c.fill(path.rect(X0, -height / 2, X1 - X0, height),
                           [color.gray(0.85)])

            # add dips if requests and already determined
            if show_dips and self.DIPs is not None:
                print(self.DIPs.shape)
                where = numpy.where(self.DIPs['chr'] == i)[0]
                if where.shape[0] == 0:
                    continue
                for j in where:
                    X0 = ((self.DIPs['coords'][j, 0] - start) /
                          float(stop - start) * width)
                    X1 = ((self.DIPs['coords'][j, 1] - start) /
                          float(stop - start) * width)
                    c.fill(path.rect(X0, -height / 2, X1 - X0, height),
                           [color.rgb.red])

            # add signal track
            c.fill(lpath)
            c.stroke(path.line(0, -height / 2, width, -height / 2))

            # add partition mean line if requested and already determined
            if show_means and self.partitions is not None:
                where = numpy.where(self.partitions['chr'] == i)[0]
                coords = ((self.partitions['coords'][where, :] - start) /
                          float(stop - start) * width)
                Ys = ((self.partitions['score'][where] / maxscore) * height *
                      0.5)
                lpath = path.path(path.moveto(0, 0))
                for j in range(Ys.shape[0]):
                    if j == 0 or coords[j, 0] != coords[j - 1, 1]:
                        lpath.append(path.lineto(coords[j, 0], 0))
                    lpath.append(path.lineto(coords[j, 0], Ys[j]))
                    lpath.append(path.lineto(coords[j, 1], Ys[j]))
                    if (j == Ys.shape[0] - 1
                            or coords[j, 1] != coords[j + 1, 0]):
                        lpath.append(path.lineto(coords[j, 1], 0))
                lpath.append(path.lineto(width, 0))
                c.stroke(lpath, [
                    color.rgb.blue, style.linewidth.THIN,
                    color.transparency(0.5)
                ])

            # add partition lines if requested and already determined
            if show_partitions and self.partitions is not None:
                where = numpy.where(self.partitions['chr'] == i)[0]
                coords = ((self.partitions['coords'][where, :] - start) /
                          float(stop - start) * width)
                for j in range(coords.shape[0] - 1):
                    c.stroke(
                        path.line(coords[j, 1], -height * 0.5, coords[j, 1],
                                  height * 0.5), [style.linewidth.THin])
                    if coords[j, 1] != coords[j + 1, 0]:
                        c.stroke(
                            path.line(coords[j + 1, 0], -height * 0.5,
                                      coords[j + 1, 0], height * 0.5),
                            [style.linewidth.THin])

            # add coordinates
            for j in range(int(numpy.ceil(start / 10000000.)),
                           int(numpy.floor(stop / 10000000.) + 1)):
                X = (j * 10000000. - start) / (stop - start) * width
                c.stroke(path.line(X, -height / 2, X, -height / 2 - 0.2))
                c.text(X, -height / 2 - 0.25, "%i Mb" % (j * 10),
                       [text.halign.center, text.valign.top])
            c.text(width * 0.5, -height / 2 - 0.6,
                   "%s" % self.chroms[i].replace('_', ' '),
                   [text.halign.center, text.valign.top])
            pages.append(document.page(c))
        doc = document.document(pages)
        doc.writePDFfile(fname)
コード例 #40
0
ファイル: t1file.py プロジェクト: mjg/PyX-svn
 def updatepath(self, path, trafo, context):
     path.append(closepath())
     # The closepath in T1 is different from PostScripts in that it does
     # *not* modify the current position; hence we need to add an additional
     # moveto here ...
     path.append(moveto_pt(*trafo.apply_pt(context.x, context.y)))
コード例 #41
0
ファイル: time_comparison.py プロジェクト: bxlab/HiFive_Paper
def plot_bargraph(data, width, height):
    methods = ['HiCLib', 'HiCPipe', 'HiCNorm', 'HiFive-Probability', 'HiFive-Binning', 'HiFive-Express',
               'HiFive-ExpressKR', 'HiFive-ExpressKR w/distance']
    ho = 4.0
    left_width = (width - ho) * 0.45
    mid_width1 = (width - ho) * 0.3
    mid_width2 = (width - ho) * 0.125
    right_width = (width - ho) * 0.125
    bar_height = height / len(methods) - 0.1
    data_totals = {}
    ranges = numpy.zeros((4, 2), dtype=numpy.float32)
    for meth in data:
        data_totals[meth] = find_total(data[meth])
        if meth == 'HiCPipe':
            ranges[1, 1] = data_totals[meth]
        elif meth == 'HiCNorm':
            ranges[2, 1] = data_totals[meth]
        elif meth == 'HiFive-Probability':
            ranges[3, 1] = data_totals[meth]
        else:
            ranges[0, 1] = max(ranges[0, 1], data_totals[meth])
    ranges /= 60.0
    ranges[0, 1] = 28.0
    ranges[1, 0] = ranges[1, 1] - ranges[0, 1] / 0.45 * 0.3 * 0.9
    ranges[1, 1] = ranges[1, 1] + ranges[0, 1] / 0.45 * 0.3 * 0.1
    ranges[2, 0] = ranges[2, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5
    ranges[2, 1] = ranges[2, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5
    ranges[3, 0] = ranges[3, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5
    ranges[3, 1] = ranges[3, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5
    c = canvas.canvas()
    g1 = graph.graphxy(width=left_width, height=height,
                       x=graph.axis.lin(painter=painter, min=0, max=ranges[0, 1]),
                       x2=graph.axis.lin(parter=None, min=0, max=ranges[0, 1]),
                       y=graph.axis.lin(parter=None, min=0, max=1),
                       y2=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g1)
    g2 = graph.graphxy(width=mid_width1, height=height,
                       x=graph.axis.lin(painter=painter, min=ranges[1, 0], max=ranges[1, 1]),
                       x2=graph.axis.lin(parter=None, min=ranges[1, 0], max=ranges[1, 1]),
                       y2=graph.axis.lin(painter=None, min=0, max=1),
                       y=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g2, [trafo.translate(left_width, 0)])
    g3 = graph.graphxy(width=mid_width2, height=height,
                       x=graph.axis.lin(painter=painter, min=ranges[2, 0], max=ranges[2, 1]),
                       x2=graph.axis.lin(parter=None, min=ranges[2, 0], max=ranges[2, 1]),
                       y2=graph.axis.lin(painter=None, min=0, max=1),
                       y=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g3, [trafo.translate(left_width + mid_width1, 0)])
    g4 = graph.graphxy(width=right_width, height=height,
                       x=graph.axis.lin(painter=painter, min=ranges[3, 0], max=ranges[3, 1]),
                       x2=graph.axis.lin(parter=None, min=ranges[3, 0], max=ranges[3, 1]),
                       y2=graph.axis.lin(parter=None, min=0, max=1),
                       y=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g4, [trafo.translate(left_width + mid_width1 + mid_width2, 0)])
    split = canvas.canvas()
    split.fill(path.path(path.moveto(-0.15, -0.2), path.lineto(0.05, 0.2), path.lineto(.15, 0.2),
               path.lineto(-0.05, -0.2), path.closepath()), [color.cmyk.White])
    split.stroke(path.line(-0.15, -0.2, 0.05, 0.2))
    split.stroke(path.line(-0.05, -0.2, 0.15, 0.2))
    c.insert(split, [trafo.translate(left_width, 0)])
    c.insert(split, [trafo.translate(left_width, height)])
    c.insert(split, [trafo.translate(left_width + mid_width1, 0)])
    c.insert(split, [trafo.translate(left_width + mid_width1, height)])
    c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, 0)])
    c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, height)])
    for i, meth in enumerate(methods):
        c.insert(plot_bar(data[meth], ranges, bar_height, left_width / ranges[0, 1], split),
                 [trafo.translate(0, height - 0.05 - bar_height * (i + 1) - i * 0.1)])
        c.text(-0.1, height * (len(methods) - i - 0.5) / len(methods), meth,
               [text.halign.right, text.valign.middle, text.size(-2)])
    c.text((width - ho) / 2.0, -0.35, "Runtime (minutes)",
           [text.halign.center, text.valign.top, text.size(-2)])
    return c
コード例 #42
0
def polygon(*points):  # pragma: no cover
    args = []
    for i, point in enumerate(points):
        args.append(path.moveto(*point) if i == 0 else path.lineto(*point))
    args.append(path.closepath())
    return path.path(*args)
コード例 #43
0
ファイル: skyalmanac.py プロジェクト: Star-Bit/PySkyAlmanac
# prepare the limits of the chart and a clippath
ulx, uly = to_chart_coord(sun_set[0], chart)
urx, ury = to_chart_coord(sun_rise[0], chart)
top_line = path.path(path.moveto(ulx, uly),
                     path.lineto(urx, ury))

llx, lly = to_chart_coord(sun_set[-1], chart)
lrx, lry = to_chart_coord(sun_rise[-1], chart)
bot_line = path.path(path.moveto(llx, lly),
                     path.lineto(lrx, lry))

rev_sun_set = sun_set[:]
rev_sun_set.reverse()
clippath = event_to_path(rev_sun_set[:] + sun_rise[:], chart, do_check=False)
clippath.append(path.closepath())

clc = canvas.canvas([canvas.clip(clippath)]) # clipped canvas for paths, text and moon
bclc = canvas.canvas([canvas.clip(clippath)]) # clipped canvas for the background and the dots

# a seperate (larger) clipping canvas for Moon phases
clippath2 = event_to_path([rev_sun_set[0]+2.0] +
        rev_sun_set[:] + [rev_sun_set[-1]-2.0], chart, do_check=False,
            xoffset=-1.6)
clippath2 = clippath2.joined(event_to_path([sun_rise[0]-2.0] +
            sun_rise[:] + [sun_rise[-1]+2.0], chart, do_check=False,
            xoffset=1.6))
clippath2.append(path.closepath())
mclc = canvas.canvas([canvas.clip(clippath2)])

make_alm_bg(bclc, begin_day_datetime, no_days, chart,
コード例 #44
0
from pyx import canvas, color, path, text, unit

text.set(text.LatexRunner)
text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
text.preamble(r'\usepackage{nicefrac}')
unit.set(xscale=1.6, wscale=1.2)

c = canvas.canvas()
side = 4
lightcolor = color.hsb(0.65, 0.2, 1)
darkcolor = color.hsb(0.65, 1, 1)
c.fill(path.path(path.moveto(0, 0),
                 path.lineto(side, 0),
                 path.arc(0, 0, side, 0, 90),
                 path.closepath()), [lightcolor])
c.stroke(path.path(path.arc(0, 0, side, 0, 90)), [darkcolor])
c.stroke(path.rect(0, 0, side, side))
ticklen = 0.15
for tick in (0, 1):
    dist = tick*side
    c.stroke(path.line(dist, 0, dist, -ticklen))
    c.text(dist, -1.5*ticklen, str(tick), [text.halign.center, text.valign.top])
    c.stroke(path.line(0, dist, -ticklen, dist))
    c.text(-1.5*ticklen, dist, str(tick), [text.halign.right, text.valign.middle])
c.text(0.4*side, 0.4*side, r'\huge$\nicefrac{\pi}{4}$',
       [text.halign.center, text.valign.middle, darkcolor])
c.writePDFfile()
コード例 #45
0
ファイル: time_comparison.py プロジェクト: bxlab/HiFive_Paper
def plot_bargraph(data, width, height):
    methods = [
        'HiCLib', 'HiCPipe', 'HiCNorm', 'HiFive-Probability', 'HiFive-Binning',
        'HiFive-Express', 'HiFive-ExpressKR', 'HiFive-ExpressKR w/distance'
    ]
    ho = 4.0
    left_width = (width - ho) * 0.45
    mid_width1 = (width - ho) * 0.3
    mid_width2 = (width - ho) * 0.125
    right_width = (width - ho) * 0.125
    bar_height = height / len(methods) - 0.1
    data_totals = {}
    ranges = numpy.zeros((4, 2), dtype=numpy.float32)
    for meth in data:
        data_totals[meth] = find_total(data[meth])
        if meth == 'HiCPipe':
            ranges[1, 1] = data_totals[meth]
        elif meth == 'HiCNorm':
            ranges[2, 1] = data_totals[meth]
        elif meth == 'HiFive-Probability':
            ranges[3, 1] = data_totals[meth]
        else:
            ranges[0, 1] = max(ranges[0, 1], data_totals[meth])
    ranges /= 60.0
    ranges[0, 1] = 28.0
    ranges[1, 0] = ranges[1, 1] - ranges[0, 1] / 0.45 * 0.3 * 0.9
    ranges[1, 1] = ranges[1, 1] + ranges[0, 1] / 0.45 * 0.3 * 0.1
    ranges[2, 0] = ranges[2, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5
    ranges[2, 1] = ranges[2, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5
    ranges[3, 0] = ranges[3, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5
    ranges[3, 1] = ranges[3, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5
    c = canvas.canvas()
    g1 = graph.graphxy(width=left_width,
                       height=height,
                       x=graph.axis.lin(painter=painter,
                                        min=0,
                                        max=ranges[0, 1]),
                       x2=graph.axis.lin(parter=None, min=0, max=ranges[0, 1]),
                       y=graph.axis.lin(parter=None, min=0, max=1),
                       y2=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g1)
    g2 = graph.graphxy(width=mid_width1,
                       height=height,
                       x=graph.axis.lin(painter=painter,
                                        min=ranges[1, 0],
                                        max=ranges[1, 1]),
                       x2=graph.axis.lin(parter=None,
                                         min=ranges[1, 0],
                                         max=ranges[1, 1]),
                       y2=graph.axis.lin(painter=None, min=0, max=1),
                       y=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g2, [trafo.translate(left_width, 0)])
    g3 = graph.graphxy(width=mid_width2,
                       height=height,
                       x=graph.axis.lin(painter=painter,
                                        min=ranges[2, 0],
                                        max=ranges[2, 1]),
                       x2=graph.axis.lin(parter=None,
                                         min=ranges[2, 0],
                                         max=ranges[2, 1]),
                       y2=graph.axis.lin(painter=None, min=0, max=1),
                       y=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g3, [trafo.translate(left_width + mid_width1, 0)])
    g4 = graph.graphxy(width=right_width,
                       height=height,
                       x=graph.axis.lin(painter=painter,
                                        min=ranges[3, 0],
                                        max=ranges[3, 1]),
                       x2=graph.axis.lin(parter=None,
                                         min=ranges[3, 0],
                                         max=ranges[3, 1]),
                       y2=graph.axis.lin(parter=None, min=0, max=1),
                       y=graph.axis.lin(painter=None, min=0, max=1))
    c.insert(g4, [trafo.translate(left_width + mid_width1 + mid_width2, 0)])
    split = canvas.canvas()
    split.fill(
        path.path(path.moveto(-0.15, -0.2), path.lineto(0.05, 0.2),
                  path.lineto(.15, 0.2), path.lineto(-0.05, -0.2),
                  path.closepath()), [color.cmyk.White])
    split.stroke(path.line(-0.15, -0.2, 0.05, 0.2))
    split.stroke(path.line(-0.05, -0.2, 0.15, 0.2))
    c.insert(split, [trafo.translate(left_width, 0)])
    c.insert(split, [trafo.translate(left_width, height)])
    c.insert(split, [trafo.translate(left_width + mid_width1, 0)])
    c.insert(split, [trafo.translate(left_width + mid_width1, height)])
    c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, 0)])
    c.insert(split,
             [trafo.translate(left_width + mid_width1 + mid_width2, height)])
    for i, meth in enumerate(methods):
        c.insert(
            plot_bar(data[meth], ranges, bar_height, left_width / ranges[0, 1],
                     split),
            [
                trafo.translate(0, height - 0.05 - bar_height *
                                (i + 1) - i * 0.1)
            ])
        c.text(-0.1,
               height * (len(methods) - i - 0.5) / len(methods), meth,
               [text.halign.right, text.valign.middle,
                text.size(-2)])
    c.text((width - ho) / 2.0, -0.35, "Runtime (minutes)",
           [text.halign.center, text.valign.top,
            text.size(-2)])
    return c
コード例 #46
0
ファイル: almanac_moon.py プロジェクト: Star-Bit/PySkyAlmanac
def last_quarter_moon(r, cx, cy) :
    p = path.path(path.moveto(cx, cy))
    p.append(path.arc(cx, cy, r, 90, -90))
    p.append(path.closepath())
    return p
コード例 #47
0
ファイル: graph.py プロジェクト: asuar078/python_workspace
 def yvgridpath(self, vy):
     return path.path(path.moveto_pt(*self.vpos_pt(0, vy, 0)),
                      path.lineto_pt(*self.vpos_pt(1, vy, 0)),
                      path.lineto_pt(*self.vpos_pt(1, vy, 1)),
                      path.lineto_pt(*self.vpos_pt(0, vy, 1)),
                      path.closepath())
コード例 #48
0
ファイル: graph.py プロジェクト: asuar078/python_workspace
 def zvgridpath(self, vz):
     return path.path(path.moveto_pt(*self.vpos_pt(0, 0, vz)),
                      path.lineto_pt(*self.vpos_pt(1, 0, vz)),
                      path.lineto_pt(*self.vpos_pt(1, 1, vz)),
                      path.lineto_pt(*self.vpos_pt(0, 1, vz)),
                      path.closepath())
コード例 #49
0
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])

c1 = canvas.canvas([canvas.clip(p)])
c1.fill(p, [color.grey(0.9)])

r = 1
brown1 = color.rgb(148 / 255, 77 / 255, 48 / 255)
brown2 = color.rgb(193 / 255, 91 / 255, 49 / 255)
red1 = color.rgb(200 / 255, 0, 0)
red2 = color.rgb(220 / 255, 0.5, 0.5)
flame = color.rgb(248 / 255, 212 / 255, 27 / 255)
c2 = canvas.canvas()
c2.insert(ellipse(r, 0.5, brown1))
c2.fill(path.rect(-r, 0, 2 * r, 0.5 * r), [brown1])
c2.insert(ellipse(r, 0.5, brown2), [trafo.translate(0, 0.5 * r)])
c2.insert(ellipse(0.2 * r, 0.5, red1), [trafo.translate(0, 0.5 * r)])
c2.fill(path.rect(-0.2 * r, 0.5 * r, 0.4 * r, r), [red1])
c2.insert(ellipse(0.2 * r, 0.5, red2), [trafo.translate(0, 1.5 * r)])
c2.stroke(path.line(0, 1.5 * r, 0, 1.5 * r + 0.2), [style.linewidth.Thick])
c2a = canvas.canvas()
c2a.fill(
    path.path(path.moveto(0, 0), path.curveto(-0.1, -0.2, -0.3, -0.6, 0, -0.6),
              path.curveto(0.3, -0.6, 0, -0.3, 0, 0), path.closepath()),
    [flame])
c2.insert(c2a, [trafo.translate(0, 1.65 * r + 0.6)])

c.insert(c1)
c.insert(c2, [trafo.translate(1.75, 1.3)])
c.insert(c2, [trafo.translate(4.7, 1.3)])
c.writeGSfile(device="png16m", resolution=300)
コード例 #50
0
 def updatepath(self, path, trafo, context):
     path.append(closepath())
     # The closepath in T1 is different from PostScripts in that it does
     # *not* modify the current position; hence we need to add an additional
     # moveto here ...
     path.append(moveto_pt(*trafo.apply_pt(context.x, context.y)))