Example #1
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()
    )
Example #2
0
 def _fret(self, x, y):
     p = path.path(
         path.moveto(x, y),
         path.lineto(x, y+5*self.fret_height),
         path.moveto(x+self.fret_width, y),
         path.lineto(x+self.fret_width, y+5*self.fret_height),
     )
     for i in range(0, 6):
         p.append(path.moveto(x, y+i*self.fret_height))
         p.append(path.lineto(x+self.fret_width, y+i*self.fret_height))
     return p
Example #3
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
Example #4
0
def makebinaries(number, y0):
    size = 0.4
    dist = 0.1
    for n in range(32):
        c.stroke(path.rect(n * size + (n / 8) * dist, y0, size, size))
        c.text((n + 0.5) * size + (n / 8) * dist, y0 + 0.07,
               r"\sffamily %i" % ((number >> 31 - n) & 1),
               [text.halign.center])

    if number >> 31:
        c.text(32.2 * size + 5 * dist, y0 + 0.07,
               r"\sffamily = -%i" % ((number ^ 0xffffffff) + 1))
    else:
        c.text(32.2 * size + 5 * dist, y0 + 0.07, r"\sffamily = %i" % number)

    p = path.path(path.moveto(0.2 * size, size + 0.03),
                  path.lineto(0.2 * size, size + 0.07),
                  path.lineto(3.8 * size, size + 0.07),
                  path.lineto(3.8 * size, size + 0.03))
    for n in range(4):
        c.stroke(p, [trafo.translate(n * (8 * size + dist), y0)])
        c.text(n * (8 * size + dist) + 2 * size, size + 0.14 + y0,
               r"\sffamily %X" % ((number >> ((3 - n) * 8 + 4)) & 15),
               [text.halign.center])
        c.stroke(p, [trafo.translate(n * (8 * size + dist) + 4 * size, y0)])
        c.text(n * (8 * size + dist) + 6 * size, size + 0.14 + y0,
               r"\sffamily %X" % ((number >>
                                   ((3 - n) * 8)) & 15), [text.halign.center])
Example #5
0
def event_to_path(event, chart, do_check=True, xoffset=0.0, yoffset=0.0) :
    '''accepts an array of points representing an event, converts this
       event to a path'''
    x, y = to_chart_coord(event[0], chart)
    p = path.path(path.moveto(x,y))
    for e in event[1:] :
        old_x = x
        old_y = y
        x, y = to_chart_coord(e, chart)
        if (do_check == False or 
            (fabs(old_x - x) < chart.width/2.0  and
             fabs(old_y - y) < chart.height/2.0)) :  
            p.append(path.lineto(x+xoffset, y+yoffset))
        else :
            p.append(path.moveto(x+xoffset, y+yoffset))
    return p
Example #6
0
def makebinaries(number, y0):
    size = 0.4
    dist = 0.1
    for n in range(32):
        c.stroke(path.rect(n*size+(n/8)*dist, y0, size, size))
        c.text((n+0.5)*size+(n/8)*dist, y0+0.07,
               r"\sffamily %i" % ((number >> 31-n) & 1),
               [text.halign.center])

    if number >> 31:
        c.text(32.2*size+5*dist, y0+0.07,
               r"\sffamily = -%i" % ((number ^ 0xffffffff)+1))
    else:
        c.text(32.2*size+5*dist, y0+0.07, r"\sffamily = %i" % number)

    p = path.path(path.moveto(0.2*size, size+0.03),
                  path.lineto(0.2*size, size+0.07),
                  path.lineto(3.8*size, size+0.07),
                  path.lineto(3.8*size, size+0.03))
    for n in range(4):
        c.stroke(p, [trafo.translate(n*(8*size+dist), y0)])
        c.text(n*(8*size+dist)+2*size, size+0.14+y0,
               r"\sffamily %X" % ((number >> ((3-n)*8+4)) & 15),
               [text.halign.center])
        c.stroke(p, [trafo.translate(n*(8*size+dist)+4*size, y0)])
        c.text(n*(8*size+dist)+6*size, size+0.14+y0,
               r"\sffamily %X" % ((number >> ((3-n)*8)) & 15),
               [text.halign.center])
Example #7
0
 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)
Example #8
0
 def drawCircle(self, r, steps=20):
     """
     Draws a circle of radius r centered on the pen.
     
     The center of the circle is the current pen coordinates. When done, the position 
     of the pen will remain unchanged
     
     :param r: radius of the circle
     :type r:  ``int`` or ``float``
     """
     from pyx import path
     import math
     assert (type(r) in [int, float]), "%s is not a valid number" % repr(r)
     for s in range(steps):
         a = (math.pi * 2 * s) / float(steps)
         x = math.cos(a) * r + self._x
         y = math.sin(a) * r + self._y
         if s == 0:
             self._pather.append(path.moveto(x, y))
         else:
             self._pather.append(path.lineto(x, y))
     x = r + self._x
     y = self._y
     self._pather.append(path.lineto(x, y))
     self._dirty = True
Example #9
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
Example #10
0
    def forward(self, distance):
        """
        Moves the turtle forward by the given amount.
        
        This method draws a line if drawmode is True.
        
        :param distance: distance to move in pixels
        :type distance:  ``int`` or ``float``
        """
        import math
        from pyx import path
        assert (type(distance)
                in [int, float]), "%s is not a valid number" % repr(distance)

        # Compute where we are going to
        dx = math.cos(self.radangle) * distance
        dy = math.sin(self.radangle) * distance

        self._x += dx
        self._y += dy

        if (self._isdown):
            self._pather.append(path.lineto(self.x, self.y))
        else:
            self._pather.append(path.moveto(self.x, self.y))
        self._dirty = True
Example #11
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])
Example #12
0
def braid(n, i, t, inverse=False):

    if not isinstance(t, list):
        t = [t]

    t = t + [style.linewidth.Thick, red, style.linecap.round]

    N = 10

    if i is None:
        items = range(n)
    else:
        assert 0<=i<i+1<n
        items = range(i)+range(i+2, n)
    
    for k in items:
        c.stroke(path.line(0.5*k, 0., 0.5*k, 1.), t)

    if i is None:
        return

    pts0 = []
    for j in range(N):
        theta = pi*j/(N-1)
        x = 0.5 * 0.5 * (cos(theta)-1.) + 0.5*(i+1)
        y = 1.*j/(N-1)
        pts0.append((x, y))

    pts1 = []
    for j in range(N):
        theta = pi*j/(N-1)
        x = 0.5 * 0.5 * (1.-cos(theta)) + 0.5*i
        y = 1.*j/(N-1)
        pts1.append((x, y))

    if inverse:
        pts0, pts1 = pts1, pts0

    pts = [path.moveto(*pts0[0])] + [path.lineto(*p) for p in pts0[1:]]
    wiggle = path.path(*pts)
    c.stroke(wiggle, [deformer.smoothed(2.0)]+t)

    c.fill(path.circle(0.5*(i+0.5), 0.5, 0.15), t+[white])

    pts = [path.moveto(*pts1[0])] + [path.lineto(*p) for p in pts1[1:]]
    wiggle = path.path(*pts)
    c.stroke(wiggle, [deformer.smoothed(2.0)]+t)
Example #13
0
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)
Example #14
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())
Example #15
0
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)
Example #16
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
Example #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
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])
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
Example #20
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
Example #21
0
 def clear(self):
     """
     Deletes the turtle's drawings from the window.
     
     This method does not move the turtle or alter its attributes.
     """
     from pyx import path
     self._window.clear()
     self._window._addTurtle(self)
     self._pather = path.path(path.moveto(self.x, self.y))
     self._dirty = False
Example #22
0
 def flush(self):
     """
     Writes the current turtle path and color to the window.
     
     PyX drawing only supports one color per path.  Therefore, this must be called
     every time the turtle changes color.
     """
     from pyx import path
     self._window.stroke(self._pather, self.color)
     self._pather = path.path(path.moveto(self.x, self.y))
     self._dirty = False
Example #23
0
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])])
Example #24
0
def mkpath(x, y, radius=1.):

    pts = []
    pts.append((x+0.07*radius, y+0.05*radius))
    pts.append((x+0.5*radius, y+0.3*radius))
    pts.append((x+0.5*radius, y-0.3*radius))
    pts.append((x+0.07*radius, y-0.05*radius))

    pts = [path.moveto(*pts[0])] + [path.lineto(*p) for p in pts[1:]]

    pts = path.path(*pts)
    return pts
Example #25
0
def spiral(radius, angle, n, dphi=5):
    phif = angle + n * 360
    npts = abs(phif) // dphi
    if abs(phif) >= 360:
        dr = 0.1 * abs(phif) / 360
    else:
        dr = 0
    p = path.path(path.moveto(radius - 0.5 * dr, 0))
    for nphi in range(1, npts + 1):
        phi = radians(phif * nphi / npts)
        r = radius - 0.5 * dr + dr * nphi / npts
        p.append(path.lineto(r * cos(phi), r * sin(phi)))
    return p
Example #26
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)
Example #27
0
def tetra(x, y, count=None, subcount=None, rev=1, back=True, front=True, reflect=False):

    if back:
        circle(x, y, r, shade)

    rr = 1.0*r
    if subcount is not None:
        ps = []
        for i in range(3):
            theta1 = rev*2*(i+subcount)*pi/3
            if i==0:
                # start of curve
                x1, y1 = x+rr*sin(theta1), y+rr*cos(theta1)
                ps.append((x1, y1))
            if i==1:
                x1, y1 = x+0.7*r*sin(theta1), y+0.7*r*cos(theta1)
                ps.append((x1, y1))
            else:
                x1, y1 = x+0.4*r*sin(theta1), y+0.4*r*cos(theta1)
                ps.append((x1, y1))
            if i==2:
                # end of curve
                x1, y1 = x+1.0*rr*sin(theta1), y+1.0*rr*cos(theta1)
                ps.append((x1, y1))
        c.stroke(path.path(
            path.moveto(*ps[0]),
            path.lineto(*ps[1]),
            path.lineto(*ps[2]), 
            path.lineto(*ps[3]), 
            path.lineto(*ps[4])), 
            st_curve+[deformer.smoothed(0.6)])

    if front:
        for theta1 in [0., 2*pi/3, 4*pi/3]:
            x1, y1 = x+0.5*r*sin(theta1), y+0.5*r*cos(theta1)
            circle(x1, y1, r0, white)

    if count is not None:

        assert 0<=count<=2
        s = 0.86*r
        r1 = 2.4*r0
        extra = []
        #c.text(x, y, count)
        if reflect:
            #count = [0, 1, 2][count]
            extra.append(trafo.scale(x=x, y=y, sx=-1, sy=1))
        extra += [trafo.rotate(-count*120, x=x, y=y)]
        t = Turtle(x1, y1-r1, -pi/2).right(pi, r1).fwd(s).right(pi, r1).fwd(s)
        t.stroke(extra)
        t.stroke(extra+[deco.earrow()])
Example #28
0
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)
 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
Example #30
0
def mkpath(x, y, radius=1.):

    pts = [
        ((x+0.05*radius, y+0.04*radius)),
        ((x+0.5*radius, y+0.20*radius)),
        ((x+0.5*radius, y-0.20*radius)),
        ((x+0.07*radius, y-0.05*radius)),
    ]

    pts = [(xx+0.8*yy, yy) for (xx, yy) in pts]

    pts = [path.moveto(*pts[0])] + [path.lineto(*p) for p in pts[1:]]

    pts = path.path(*pts)
    return pts
Example #31
0
def filesymbol(size, symbolcolor):
    wd = size
    ht = size * 1.414
    knick = 0.25 * wd
    p = path.path(path.moveto(0.5 * wd - knick, 0.5 * ht),
                  path.lineto(0.5 * wd, 0.5 * ht - knick),
                  path.lineto(0.5 * wd, -0.5 * ht),
                  path.lineto(-0.5 * wd, -0.5 * ht),
                  path.lineto(-0.5 * wd, 0.5 * ht),
                  path.lineto(0.5 * wd - knick, 0.5 * ht),
                  path.lineto(0.5 * wd - knick, 0.5 * ht - knick),
                  path.lineto(0.5 * wd, 0.5 * ht - knick))
    cf = canvas.canvas()
    cf.stroke(p, [symbolcolor, style.linewidth.Thick, style.linejoin.round])
    return cf
Example #32
0
def waning_moon(X, r, cx, cy) :
    '''draws a waning moon figure, used for moonrise.'''
    p = path.path(path.moveto(cx, cy+r))
    p.append(path.arc(cx, cy, r, 90, -90))
    if X>0.5 :
        R = R_of_S(X-0.5)*r
        theta = asin(r/R)*180/PI
        moon_arc_p = path.arc(cx-sqrt(R*R-r*r), cy, R, -theta, theta)
    else :
        R = R_of_S(0.5-X)*r
        theta = asin(r/R)*180/PI
        moon_arc_p = path.arc(cx+sqrt(R*R-r*r), cy, R, 180-theta, 180+theta)
        p = path.path.reversed(p)
    p.append(moon_arc_p)
    return p
Example #33
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])
 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
Example #35
0
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")
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])
Example #37
0
def wiggle(x0, y0, radius, wiggle=0.3, n=1):
    seed(n)
    
    items = []
#    theta = 0.
    theta = 2*pi
    while theta > 0:
        r = radius + wiggle*random()
        p = [x0+r*sin(theta), y0+r*cos(theta)]
        items.append(p)
        theta -= 0.3*pi*random()
    
    #print items
    items = [path.moveto(*items[0])] + [path.lineto(*p) for p in items[1:]]\
        + [path.lineto(*items[0])] 
    items = path.path(*items)

    return items
Example #38
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))
Example #39
0
    def __init__(self,
                 screen,
                 position=(0, 0),
                 color='red',
                 heading=180,
                 speed=0):
        """
        Creates a new turtle to draw on the given screen.
        
        :param screen: window object that turtle will draw on.
        :type screen:  :class:`Window`
        
        :param position: initial turtle position (origin is screen center)
        :type position:  2D ``tuple``
        
        :param color: initial turtle color (default red)
        :type color: see ``color``
        
        :param heading: initial turtle directions (default 180)
        :type heading:  ``int`` or ``float``
        
        :param speed: initial turtle speed (default 0)
        :type speed:  ``int`` 0..10
        """
        from .window import Window, is_valid_color, to_valid_color
        from pyx import path
        assert type(
            screen) == Window, "$s is not a Window object" % repr(screen)
        assert (is_valid_color(color)
                ), "%s is not a valid color input" % repr(color)

        self._window = screen
        screen._addTurtle(self)
        self._heading = heading
        self._isdown = True
        self._speed = speed
        self._visible = True
        self._dirty = False

        self._color = to_valid_color(color)

        self._x = position[0]
        self._y = position[1]
        self._pather = path.path(path.moveto(self.x, self.y))
Example #40
0
 def move(self, x, y):
     """
     Moves the turtle to given position without drawing.
     
     This method does not draw, regardless of the drawmode.
     
     :param x: new x position for turtle
     :type x:  ``int`` or ``float``
     
     :param y: new y position for turtle
     :type y:  ``int`` or ``float``
     """
     from pyx import path
     assert (type(x) in [int, float]), "%s is not a valid number" % repr(x)
     assert (type(y) in [int, float]), "%s is not a valid number" % repr(y)
     self._x = x
     self._y = y
     self._pather.append(path.moveto(x, y))
     self._dirty = True
Example #41
0
 def move(self, x, y):
     """
     Moves the pen to given position without drawing.
     
     If the ``fill`` attribute is currently True, this method will complete the fill 
     before moving to the new region. The space between the original position and (x,y) 
     will not be connected.
     
     :param x: new x position for turtle
     :type x:  ``int`` or ``float``
     
     :param y: new y position for turtle
     :type y:  ``int`` or ``float``
     """
     from pyx import path
     assert (type(x) in [int, float]), "%s is not a valid number" % repr(x)
     assert (type(y) in [int, float]), "%s is not a valid number" % repr(y)
     self._x = x
     self._y = y
     self._pather.append(path.moveto(x, y))
     self._dirty = True
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
Example #43
0
    def pyx_plotter(self):
        from pyx import canvas, path, color

        st = Stats(self.points)

        if self.plot_range == AUTO:
            xmax, xmin, ymax, ymin = st.bbox_auto(self.points)
        else:
            xmax, xmin, ymax, ymin = st.bbox()
        wd, ht = xmax - xmin, ymax - ymin

        sx = self.default_width / wd
        sy = self.aspect_ratio * self.default_width / ht
        #print 'WD:', wd, 'HT:', ht, sx, sy

        clip = canvas.clip(path.rect(sx * xmin, sy * ymin, sx * wd, sy * ht))

        c = canvas.canvas([clip])
        #c.stroke(path.rect(sx*xmin, sy*ymin, sx*wd, sy*ht))

        pth = path.path()
        first_point = True

        for p in self.points:
            if first_point:
                pth.append(path.moveto(sx * p.x, sy * p.y))
                first_point = False
            else:
                pth.append(path.lineto(sx * p.x, sy * p.y))

        c.stroke(pth)

        for p in self.points:
            if st.is_extreme_outlier(p):
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03), [color.rgb.red])
            else:
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03))
        return c
Example #44
0
    def pyx_plotter(self):
        from pyx import canvas, path, color

        st = Stats(self.points)

        if self.plot_range == AUTO:
            xmax, xmin, ymax, ymin = st.bbox_auto(self.points)
        else:
            xmax, xmin, ymax, ymin = st.bbox()
        wd, ht = xmax - xmin, ymax - ymin

        sx = self.default_width / wd
        sy = self.aspect_ratio * self.default_width / ht
        #print 'WD:', wd, 'HT:', ht, sx, sy

        clip = canvas.clip(path.rect(sx * xmin, sy * ymin, sx * wd, sy * ht))

        c = canvas.canvas([clip])
        #c.stroke(path.rect(sx*xmin, sy*ymin, sx*wd, sy*ht))

        pth = path.path()
        first_point = True

        for p in self.points:
            if first_point:
                pth.append(path.moveto(sx * p.x, sy * p.y))
                first_point = False
            else:
                pth.append(path.lineto(sx * p.x, sy * p.y))

        c.stroke(pth)

        for p in self.points:
            if st.is_extreme_outlier(p):
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03), [color.rgb.red])
            else:
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03))
        return c
Example #45
0
def make_arc(a, b, return_midpt=False):
    det = 4 * (a.real * b.imag - a.imag * b.real)
    if abs(det) < 0.0001:
        if not return_midpt:
            return make_line(a, b)
        else:
            return (make_line(a,
                              b), (0.5 * (a[0] + b[0]), 0.5 * (a[1] + b[1])))
    else:
        # theta = 0.5 * acos( a[0]*b[0] + a[1]*b[1] )
        # r = tan(theta)
        # p = path.path( path.moveto(a[0], a[1]) )
        # p.append( path.arct(0.0,0.0,b[0], b[1], r))

        center, r = arc_center_rad(a, b)
        A2 = a - center
        B2 = b - center
        r = abs(A2)
        dot_prod = (A2.real * B2.real + A2.imag * B2.imag)
        theta = 0.5 * acos(dot_prod / (abs(A2) * abs(B2)))
        direction = (0.5 * (a + b) - center)
        direction = (1.0 / abs(direction)) * direction
        tangent_point = center + (abs(A2) / cos(theta)) * direction

        p = path.path(path.moveto(a.real, a.imag))
        p.append(
            path.arct(tangent_point.real, tangent_point.imag, b.real, b.imag,
                      r))

        # p = path.path( path.moveto(a[0], a[1]) )
        # p.append( path.lineto(center.real, center.imag) )
        # p.append( path.lineto(b[0], b[1]) )
        if not return_midpt:
            return p
        else:
            midpt = center + r * direction
            return (p, midpt)
projector = graph.graphxyz.central(60, -50, 25).point

unit.set(wscale=1.5)
c = canvas.canvas()
nxmax = 7
nymax = 5
trans = 0.4
edgecolors = (color.rgb(0, 0, 0.8),
              color.rgb(0, 0.6, 0),
              color.rgb(0.8, 0, 0))
w = 0.3
facecolors = (color.rgb(w, w, 1),
              color.rgb(w, 1, w),
              color.rgb(1, w, w))
for nplane, (edgecolor, facecolor) in enumerate(zip(edgecolors, facecolors)):
    zoff = 1.04*(2-nplane)
    frontplane(zoff+1, nxmax, nymax, facecolor, edgecolor, trans)
    for nx in range(nxmax, -1, -1):
        for ny in range(nymax+1):
            corner(nx, ny, zoff, facecolor, edgecolor, trans,
                   nx != 0, ny != nymax)
    frontplane(zoff, nxmax, nymax, facecolor, edgecolor, trans)
    x0, y0 = projector(nxmax, zoff+1, nymax)
    x1, y1 = projector(0, zoff+1, nymax)
    x2, y2 = projector(0, zoff+1, 0)
    p = path.path(path.moveto(x0, y0), path.lineto(x1, y1),
                  path.lineto(x2, y2))
    c.stroke(p, [edgecolor])
c.writePDFfile()
Example #47
0
codepointbinary = [(codepoint & 2**n)/2**n for n in range(bits)]
codepointbinary.reverse()

size = 0.4
x0 = 0
y0 = 3
dy = 0.07
c.fill(path.rect(x0, y0, 5*size, size),
       [color.grey(0.5), deco.stroked([color.grey(0.5)])])
c.stroke(path.rect(x0+5*size, y0, 5*size, size))
c.stroke(path.rect(x0+10*size, y0, 6*size, size))
for n in range(len(codepointbinary)):
    c.text(x0+(n+0.5)*size, y0+dy, r"\sffamily %i" % codepointbinary[n],
           [text.halign.center])

p = path.path(path.moveto(0.2*size, size+0.03),
              path.lineto(0.2*size, size+0.07),
              path.lineto(3.8*size, size+0.07),
              path.lineto(3.8*size, size+0.03))
for n in range(bits//4):
    c.stroke(p, [trafo.translate(4*n*size, y0)])
    c.text((4*n+2)*size, size+0.14+y0, r"\sffamily %X" %
           (codepoint >> (bits//4-n-1)*4 & 0x0f),
           [text.halign.center])

utf8code = 0xC080 \
           + (((codepoint >> 6) & 0x1f) << 8) \
           + (codepoint & 0x3f)
utf8codebinary = [(utf8code & 2**n)/2**n for n in range(bits)]
utf8codebinary.reverse()
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()
Example #49
0
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
for nr, elem in enumerate((ex1color, ex2color, ex3color)):
    preamble = preamble+r'\definecolor{{ex{}color}}{{rgb}}{{{}, {}, {}}}'.format(
                  nr+1, elem.r, elem.g, elem.b)
text.preamble(preamble)
unit.set(xscale=1.2)

c = canvas.canvas()
for n in range(5):
    framebox(n+1, ncols-n-1, ex1color)
for nx in (0, 2, 5):
    framebox(nx, 0, ex2color, nh=3, reducedsize=True)
for n in (0, 2, 5):
    framebox(2, (ncols-n-1), ex3color)

for nx in range(ncols+1):
    p = path.path(path.moveto(nx*boxsize, 0),
                  path.lineto(nx*boxsize, ncols*boxsize),
                  path.rlineto(reducedboxsize*cos(angle), reducedboxsize*sin(angle)))
    c.stroke(p)
for ny in range(nrows+1):
    p = path.path(path.moveto(0, ny*boxsize),
                  path.lineto(nrows*boxsize, ny*boxsize),
                  path.rlineto(reducedboxsize*cos(angle), reducedboxsize*sin(angle)))
    c.stroke(p)
p = path.path(path.moveto(ncols*boxsize+reducedboxsize*cos(angle),
                          reducedboxsize*sin(angle)),
              path.rlineto(0, ncols*boxsize),
              path.rlineto(-nrows*boxsize, 0),
              path.rlineto(-reducedboxsize*cos(angle), -reducedboxsize*sin(angle)))
c.stroke(p)
Example #51
0
    for sb in setting_bodies :
        sb.update_setting(obs)

pyx.unit.set(defaultunit='cm')
pyx.text.set(mode='latex')
pyx.text.preamble(r'\usepackage[utf8]{inputenc}')
pyx.text.preamble(r'\usepackage[T1]{fontenc}')
pyx.text.preamble(r'\usepackage{ae,aecompl}')
pyx.text.preamble(r'\usepackage{rotating}')

c = canvas.canvas()

# 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
Example #52
0
from pyx import canvas, path, style, text, unit

text.set(text.LatexRunner)
unit.set(xscale=0.8)

b = 0.8

c = canvas.canvas()
offset = 0
c.stroke(path.rect(offset, 0, b, b))
c.stroke(path.path(path.moveto(offset+0.1*b, -0.1),
                   path.lineto(offset+0.1*b, -1.2),
                   path.lineto(offset+0.3*b, -1.2)), [style.linewidth.thin])
c.text(offset+0.2*b, -1.1, r"\sffamily Vorzeichen")
c.text(0.5*b, 1.1*b, r"\sffamily 1 Bit", [text.halign.center])
c.text(0.5*b, 0.5*b, r"\sffamily S", [text.halign.center, text.valign.middle])
offset = 1.2*b
c.stroke(path.path(path.moveto(offset+0.5*b, b),
                   path.lineto(offset, b),
                   path.lineto(offset, 0),
                   path.lineto(offset+0.5*b, 0)))
c.stroke(path.path(path.moveto(offset+0.1*b, -0.1),
                   path.lineto(offset+0.1*b, -0.7),
                   path.lineto(offset+0.3*b, -0.7)), [style.linewidth.thin])
c.text(offset+0.2*b, -0.6, r"\sffamily Exponent")
offset = offset+0.5*b
c.stroke(path.line(offset, 0, offset+b, 0), [style.linestyle.dotted])
c.stroke(path.line(offset, b, offset+b, b), [style.linestyle.dotted])
c.text(offset+0.5*b, 1.1*b, r"\sffamily 11 Bits", [text.halign.center])
c.text(offset+0.5*b, 0.5*b, r"\sffamily E",
       [text.halign.center, text.valign.middle])
Example #53
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)
Example #54
0
x0 = 0
y0 = 3
dy = 0.07
c.fill(path.rect(x0, y0, 8 * size, size),
       [markercolor, deco.stroked([markercolor])])
c.stroke(path.rect(x0 + 8 * size, y0, 4 * size, size),
         [deco.filled([codecolor])])
c.stroke(path.rect(x0 + 12 * size, y0, 6 * size, size),
         [deco.filled([codecolor])])
c.stroke(path.rect(x0 + 18 * size, y0, 6 * size, size),
         [deco.filled([codecolor])])
for n in range(len(codepointbinary)):
    c.text(x0 + (n + 0.5) * size, y0 + dy,
           r"\sffamily %i" % codepointbinary[n], [text.halign.center])

p = path.path(path.moveto(0.2 * size, size + 0.03),
              path.lineto(0.2 * size, size + 0.07),
              path.lineto(3.8 * size, size + 0.07),
              path.lineto(3.8 * size, size + 0.03))
for n in range(bits // 4):
    c.stroke(p, [trafo.translate(4 * n * size, y0)])
    c.text((4 * n + 2) * size, size + 0.14 + y0,
           r"\sffamily %X" % (codepoint >> (bits // 4 - n - 1) * 4 & 0x0f),
           [text.halign.center])

utf8code = 0xE08080 \
           + (((codepoint >> 12) & 0x0f) << 16) \
           + (((codepoint >> 6) & 0x3f) << 8) \
           + (codepoint & 0x3f)
utf8codebinary = [(utf8code & 2**n) / 2**n for n in range(bits)]
utf8codebinary.reverse()
Example #55
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
Example #56
0
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
Example #57
0
    for sb in setting_bodies :
        sb.update_setting(obs)

pyx.unit.set(defaultunit='cm')
pyx.text.set(mode='latex')
pyx.text.preamble(r'\usepackage[utf8]{inputenc}')
pyx.text.preamble(r'\usepackage[T1]{fontenc}')
pyx.text.preamble(r'\usepackage{ae,aecompl}')
pyx.text.preamble(r'\usepackage{rotating}')

c = canvas.canvas()

# 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] +
Example #58
0
pop([trafo.rotate(-90), trafo.translate(0.7, 2.5*h)])
c.text(0., 0.5*h, "(a)")

# --------------------------------------------------------------------

#x0, y0 = 0.6, 0.
    
#c.text(x0-0.8, y0, "(b)")
push()

c.stroke(path.rect(x0, y0, w, h), dashed)
c.stroke(path.rect(x0+w+m, y0, w, h), dotted)


p = path.path(
    path.moveto(x0+0.5*w, y0-0.3*h), 
    path.lineto(x0+0.5*w, y0+0.3*h), 
    path.lineto(x0+1.5*w+m, y0+0.3*h),
    path.lineto(x0+1.5*w+m, y0+0.7*h), 
    path.lineto(x0+0.5*w, y0+0.7*h),
    path.lineto(x0+0.5*w, y0+1.3*h),
)
c.stroke(p, [deformer.smoothed(0.3)]+grarrow)

y = y0+0.3*h
anyon(x0+0.8*w, y)
anyon(x0+m+1.2*w, y)
    
y = y0+0.7*h
anyon(x0+0.8*w, y)
anyon(x0+m+1.2*w, y)
Example #59
0
idx = 0 # start
points.insert(idx, (1.3*dx, -0.7*dy)); idx+=3 # next pair
points.insert(idx, (1.3*dx, -2.7*dy)); idx+=1
points.insert(idx, (1.5*dx, -2.7*dy)); idx+=1
points.insert(idx, (1.5*dx, -2.*dy)); idx+=1
points.insert(idx, (1.5*dx, -1.4*dy)); idx+=3 # next pair
points.insert(idx, (3.7*dx, -1.4*dy)); idx+=1
points.insert(idx, (3.7*dx, -1.6*dy)); idx+=1
points.insert(idx, (1.7*dx, -1.6*dy)); idx+=3 # next pair
points.insert(idx, (1.7*dx, -3.3*dy)); # end

items = []
for i, p in enumerate(points):
    if i==0:
        items.append(path.moveto(*p))
    else:
        items.append(path.lineto(*p))

c.stroke(path.path(*items),
    [trafo.translate(tx0, ty0), lred, deformer.smoothed(2.0),
    style.linewidth.THICk, deco.earrow(size=0.3)])

for (s, t) in [(0, 1), (2, 3), (4, 5)]:
    pair(points0[s], points0[t])


y -= 4.*dy
c.text(x, y,
r"""When we yank the red line straight
we find out what braid moves to do:
Example #60
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)