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
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
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])
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])
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
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
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())
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()])
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
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
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
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)
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)
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)
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)
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
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
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
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 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
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
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
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
def drawTo(self, x, y): """ Draws a line from the current pen position to (x,y) When done, the pen will be at (x, y). :param x: finishing x position for line :type x: ``int`` or ``float`` :param y: finishing y position for line :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.lineto(x, y)) self._dirty = True
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 drawLine(self, dx, dy): """ Draws a line segment (dx,dy) from the current pen position The line segment will run from (x,y) to (x+dx,y+dy), where (x,y) is the current pen position. When done, the pen will be at position (x+dx,y+dy) :param dx: change in the x position :type dx: ``int`` or ``float`` :param dy: change in the y position :type dy: ``int`` or ``float`` """ from pyx import path assert (type(dx) in [int, float]), "%s is not a valid number" % repr(dx) assert (type(dy) in [int, float]), "%s is not a valid number" % repr(dy) self._x += dx self._y += dy self._pather.append(path.lineto(self._x, self._y)) self._dirty = True
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
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 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)
from math import atan, degrees from pyx import canvas, color, path, style, text, unit unit.set(xscale=0.8) c = canvas.canvas() c.fill(path.circle(0, 0, 0.1), [color.grey(0.5)]) c.fill(path.circle(2, 1, 0.1), [color.grey(0.5)]) c.stroke(path.line(0, 0, -1., -0.2), [style.linewidth.Thick, style.linestyle.dotted]) c.stroke(path.line(2, 1, 2.7, 1.7), [style.linewidth.Thick, style.linestyle.dotted]) c.stroke(path.line(0, 0, 2, 1), [style.linewidth.thick]) c.stroke(path.path(path.moveto(0, 0), path.lineto(2, 0), path.lineto(2, 1))) c.text(0.5, 0.1, r'$\varphi$') c.stroke(path.path(path.arc(0, 0, 0.8, 0, degrees(atan(0.5))))) c.text(1, 0.6, r'$\ell=1$', [text.halign.right]) c.text(1, -0.1, r'$\cos(\varphi)$', [text.halign.center, text.valign.top]) c.text(2.1, 0.5, r'$\sin(\varphi)$', [text.valign.middle]) c.writeGSfile(device='pnggray', resolution=200)
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
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)
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)
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
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)
\usepackage{newtxsf}''') unit.set(vscale=1.2, wscale=1.3, xscale=1.3) c = canvas.canvas() c.stroke(path.line(0, 0, width, 0), [deco.earrow]) c.text(width + 0.1, 0, '$t$', [text.valign.middle]) c.stroke(path.line(0, lowertick, 0, height), [deco.earrow]) c.text(0.2, height, '$q$', [text.valign.top]) n = 6 for nt in range(n + 1): t = nt * tmax / n c.stroke(path.line(t, 0, t, lowertick)) c.stroke(path.line(t, 0, t, height - 0.26), [style.linestyle.dashed]) seed(424242) positions = [(height - 0.3) * random() for _ in range(n - 1)] positions.append(qf) p = path.path(path.moveto(0, qi)) for nt, q in enumerate(positions): p.append(path.lineto((nt + 1) * tmax / n, q)) c.stroke(p, [style.linejoin.round, color.rgb(0.2, 0, 0.8)]) c.text(0, -0.55, '$0$', [text.halign.center]) c.text(3 * tmax / n, -0.55, '$n{-}1$', [text.halign.center]) c.text(4 * tmax / n, -0.55, '$n$', [text.halign.center]) c.text(tmax, -0.55, '$N$', [text.halign.center]) for x, y in ((0, qi), (tmax, qf)): c.fill(path.circle(x, y, 0.04), [color.grey(1), deco.stroked([color.grey(0)])]) c.text(-0.1, qi, r'$q_\text{i}$', [text.halign.right, text.valign.middle]) c.text(tmax + 0.1, qf, r'$q_\text{f}$', [text.valign.middle]) c.text(width - 0.2, height - 0.26, '$N={}$'.format(n), [text.valign.top]) c.writePDFfile()
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])
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()
x0, y0 = projector(nx, z, ny) x1, y1 = projector(nx, z + 1, ny) c.stroke(path.line(x0, y0, x1, y1), [edgecolor]) 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()
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
c = canvas.canvas() x = 0. y = 0. m = 0.1*w m0 = m/2 r = 0.3*w c.fill(path.rect(x-m0, y-m0, 2*m0+w, 2*m0+h), [shade]) c.stroke(path.rect(x, y, w, h)) p = path.path( path.moveto(x+r, y-m), path.lineto(x+r, y), path.arc(x, y, r, 0, 90), path.lineto(x-m, y+r), ) c.stroke(p, g_curve+[trafo.scale(1.0, 1.3, x=x, y=y-m)]) c.stroke(path.line(x+0.5*w, y-m, x+0.5*w, y+h+m), g_curve) r = 0.2*w p = path.path( path.moveto(x+w+m, y+0.5*h+r), path.lineto(x+w, y+0.5*h+r), path.arc(x+w, y+0.5*h, r, 90, 270), path.lineto(x+w+m, y+0.5*h-r), ) c.stroke(p, g_curve+[trafo.scale(1.4, 1.0, x=x+1.*w+m, y=y+0.5*h)])
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
name = os.path.splitext(sys.argv[0])[0] + '_{}' for norder in range(4): c = canvas.canvas() file(c, yoff=2.5, title='JuliaSet', attrs=set_myattrs(norder, 0)) file(c, xoff=1, yoff=0, title=r'$\sim${}ColorRepresentation', attrs=set_myattrs(norder, 1)) file(c, xoff=1, yoff=-2.5, title=r'$\sim${}Grid', attrs=set_myattrs(norder, 2)) file(c, xoff=1, yoff=-5, title=r'$\sim${}JuliaIteration', attrs=set_myattrs(norder, 3)) c.stroke( path.path(path.moveto(0.3, 2.4), path.lineto(0.3, 0.2), path.lineto(0.9, 0.2)), [deco.earrow]) c.stroke( path.path(path.moveto(0.3, 0.1), path.lineto(0.3, -2.3), path.lineto(0.9, -2.3)), [deco.earrow]) c.stroke( path.path(path.moveto(0.3, -2.4), path.lineto(0.3, -4.8), path.lineto(0.9, -4.8)), [deco.earrow]) c.writePDFfile(name.format(norder + 1))
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] +
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) for nx in range(ncols):
def make_line(a, b): p = path.path(path.moveto(a.real, a.imag)) p.append(path.lineto(b.real, b.imag)) return p
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() y1 = 2
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()
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() )
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()
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()
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: """, [text.parbox(dw-2*m),])
codepointbinary.reverse() size = 0.4 x0 = 0 y0 = 3 dy = 0.07 c.fill(path.rect(x0, y0, 5*size, size), [markercolor, deco.stroked([markercolor])]) c.stroke(path.rect(x0+5*size, y0, 5*size, size), [deco.filled([codecolor])]) c.stroke(path.rect(x0+10*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 = 0xC080 \ + (((codepoint >> 6) & 0x1f) << 8) \ + (codepoint & 0x3f) utf8codebinary = [(utf8code & 2**n)/2**n for n in range(bits)] utf8codebinary.reverse() y1 = 2