def circ(x, y, txt): p = path.circle(x, y, 0.5*r0) st_scale = [trafo.scale(x=x, y=y, sx=1., sy=sy)] c.fill(p, st_scale+[shade2]) c.stroke(p, st_scale) c.fill(path.circle(x, y-sy*0.5*r0, 0.05)) c.text(x-0.5*r0, y+0.5*r0, txt, center)
def _penta_dots(self, c, intervals=False): penta_notes = tuple([i['note'] for i in self.penta]) def ival_by_idx(idx, minor): return ('1', 'b3', '4', '5', 'b7')[idx] if minor else ('1', '2', '3', '5', '6')[idx] for fret in range(0, self.frets + 1): for string in range(0, 6): note = self._interval( self.tones.index(self.tuning[string]), fret) if note['note'] in penta_notes: idx = penta_notes.index(note['note']) fret_x = self.x if fret == 0 else ( fret - 1) * self.fret_width + float(self.fret_width/2) if idx != 0: styles = [style.linewidth.Thick, deco.filled( [color.rgb.black])] if not intervals else [style.linewidth.Thick, deco.filled([color.rgb.white])] c.stroke(path.circle(fret_x, self.y + string * self.fret_height, self.note_rad), styles) if intervals: tx = ival_by_idx(idx, self.ptype['minor']) c.text(fret_x - self.dot_rad * (1.2 * len(tx)), self.y + string * self.fret_height - self.dot_rad, tx) else: # root note styles = [style.linewidth.Thick, deco.filled( [color.rgb.black])] if not intervals else [style.linewidth.Thick, deco.filled([color.rgb.white])] c.stroke(path.circle(fret_x, self.y + string * self.fret_height, self.note_rad), [style.linewidth.Thick, deco.filled([color.rgb.red])]) if intervals: tx = ival_by_idx(idx, self.ptype['minor']) c.text(fret_x - self.dot_rad * (1.2 * len(tx)), self.y + string * self.fret_height - self.dot_rad, tx, [color.rgb.white])
def state(x0, y0, r, c): x1 = x0 - r / sqrt(2) y1 = y0 + r / sqrt(2) x2 = x0 - 3 * r / 4 / sqrt(2) y2 = y1 + r / 8 x3 = x0 - r / 4 / sqrt(2) y3 = y1 - r / 8 x4 = x0 + r / 4 / sqrt(2) y4 = y1 + r / 8 x5 = x0 + 3 * r / 4 / sqrt(2) y5 = y1 - r / 8 x6 = x0 + r / sqrt(2) y6 = y1 delta = r / 40 c.fill(path.circle(x0, y0, r), [color.cmyk.RoyalBlue]) c.fill(path.rect(x1 + delta, y0 + delta, r * sqrt(2) - 2 * delta, r), [color.rgb.white]) inside = path.curve(x1, y1, x2, y2, x3, y3, x0, y1) << \ path.curve(x0, y1, x4, y4, x5, y5, x6, y6) << \ path.line(x6, y6, x6, y0) << \ path.line(x6, y0, x1, y0) inside.append(path.closepath()) c.fill(inside, [color.cmyk.RoyalBlue]) c.stroke(path.circle(x0, y0, r), [style.linewidth(r / 25)])
def ucirc(): x1, y1 = x-dx*r, y-r st_scale = [trafo.scale(x=x1, y=y1, sx=1., sy=sy)] c.fill(path.circle(x1, y1, 0.5*r0), st_scale+[shade0]) c.stroke(path.path(path.arc(x1, y1, 0.5*r0, 180., 0.)), st_scale) x2, y2 = x1-0.5*dx*sy*r0, y1-0.5*sy*r0 c.stroke(path.line(x, y, x2, y2)) c.fill(path.circle(x2, y2, 0.05)) c.text(x2-0.5*r0, y2-0.5*r0, "${c}$", southeast)
def put_label(x, y, nr): r = 0.3 label = r'\textsf{{\bfseries {}}}'.format(nr) if abs(x) == abs(y): c.fill(path.circle(x, y, r), [color.rgb.black]) c.text(x, y, label, [text.halign.center, text.valign.middle, color.rgb.white]) else: c.stroke(path.circle(x, y, r), [deco.filled([color.rgb.white])]) c.text(x, y, label, [text.halign.center, text.valign.middle])
def manifold(x, y, labels, count): if count in [0, 2]: c.stroke(path.line(x-r0, y, x+r1+r0, y), st_curve) else: extra = list(st_curve) #if count==3: # extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1)) Turtle(x-0.85*r0, y, pi/2).\ fwd(0.3).\ right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\ fwd(0.55).\ right(0.88*pi, 0.15).right(0.50*pi, 0.73).\ left(0.25*pi, 0.52).goto(x+r1+r0, y).\ stroke(extra) if count==0: c.text(x+r1+r0, y-0.2, "$f$", northwest) else: c.text(x+r1+r0, y-0.2, "$R^{a_1a_2}_{b_1}f$", northwest) c.text(x+(r0+r1)/2, y+0.7, "$f'$", southwest) if count == 0: Turtle(x, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*r1).stroke(st_target+[trafo.scale(x=x, y=y, sx=1, sy=-1)]) elif count == 3: Turtle(x-0.05, y, 0.90*pi).left(0.30*pi, 0.8).left(0.3*pi, 2.8).\ stroke(st_target+[trafo.scale(x=x, y=y, sx=1, sy=-1)]) else: Turtle(x+r0, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*(r1-r0)).stroke(st_target) for i in range(3): _x = [x, x+r0, x+r1][i] p = path.circle(_x, y, 0.08) c.fill(p, [white]) c.stroke(p) ydelta = -0.25 xdelta = 0.00 if count==3 and labels[i]=="a_2": ydelta = -0.35 xdelta = +0.1 if count==3 and labels[i]=="a_1": xdelta = -0.1 ydelta = +0.3 c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], center) x1 = x+(r0+r1)/2. c.text(x1, y-0.2, "...", north) c.fill(path.rect(x1-0.4, y-0.1, 0.8, 0.2), [white]) c.stroke(path.line(x1-0.4, y, x1+0.4, y), [green, style.linewidth.THick]+st_dotted) c.stroke(path.circle(x+r0/2, y, r0), [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)]) c.text(x, y+0.3*h, "$b_1$", southeast)
def surface(x, y, r, fill=shade, mark=False, orient=None): p = path.circle(x, y, r) if fill is not None: c.fill(p, [fill]) c.stroke(p) if orient == True: c.stroke(p, [deco.earrow()]) elif orient == False: c.stroke(p, [deco.earrow(), trafo.scale(x=x, y=y, sx=1, sy=-1)]) if mark: p = path.circle(x, y-r, 0.06) c.fill(p)
def draw_matrix(M, flow=None): st_text = center rows = M.rows cols = M.cols dx = 0.5 dy = 0.5 H = len(rows) * dy W = len(cols) * dx layout = {} for i, col in enumerate(cols): x, y = i * dx, H + dy layout[col] = x, y cvs.text(x, y, "$%s$" % col, st_text) for j, row in enumerate(rows): x, y = -dx, H - j * dy layout[row] = x, y cvs.text(x, y, "$%s$" % row, st_text) cvs.stroke(path.line(-1.4 * dx, H + 0.5 * dy, W - 0.5 * dx, H + 0.5 * dy)) cvs.stroke(path.line(-0.5 * dx, 0.6 * dy, -0.5 * dx, H + 1.4 * dy)) for i, col in enumerate(cols): for j, row in enumerate(rows): value = M[row, col] if value == 0: c = '.' else: c = str(value) x, y = i * dx, H - j * dy layout[row, col] = x, y cvs.text(x, y, "$%s$" % c, st_text) if flow is None: return r = 0.2 critical = flow.get_critical() for item in rows + cols: if item in critical: x, y = layout[item] cvs.stroke(path.circle(x, y, r), st_thick + [red]) for key in flow.get_pairs(): if key not in layout: continue x, y = layout[key] cvs.stroke(path.circle(x, y, r), st_thick + [orange])
def _dots(self, c): for i in range(1, self.frets + 1): if i in self.dotted: c.fill( path.circle(self.x + (i - 1)*self.fret_width + float(self.fret_width/2), self.y + 2.5 * self.fret_height, self.dot_rad) ) elif i in self.double_dotted: c.fill(path.circle(self.x + (i-1) * self.fret_width + float(self.fret_width/2), self.y + 1.5 * self.fret_height, self.dot_rad)) c.fill(path.circle(self.x + (i-1)*self.fret_width + float(self.fret_width/2), self.y + 3.5 * self.fret_height, self.dot_rad))
def make_moon_stuff(outer_canv, inner_canv, begin_day, no_days, chart, obs): small_moon_rad = 0.12 large_moon_rad = 0.16 moon = ephem.Moon() moon2 = ephem.Moon() for doy in range(no_days) : obs.date = begin_day + doy mpc = obs.date + 0.5 # moon phase check moon_set = obs.next_setting(moon) moon2.compute(moon_set) X = moon2.moon_phase # Waxing moon (moonsets) x, y = to_chart_coord(moon_set, chart) if (fabs(ephem.next_full_moon(mpc) - mpc) < 0.5 or fabs(ephem.previous_full_moon(mpc) - mpc) < 0.5) : # full moon outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) elif ((X < 0.55 and X > 0.45) or fabs(ephem.next_first_quarter_moon(mpc) - mpc) < 0.5 or fabs(ephem.previous_first_quarter_moon(mpc) - mpc) < 0.5) : # first quarter outer_canv.stroke(first_quarter_moon(large_moon_rad, x,y),[mooncolordark,pyx.deco.filled([mooncolordark])]) elif (fabs(ephem.next_new_moon(mpc) - mpc) < 0.5 or fabs(ephem.previous_new_moon(mpc) - mpc) < 0.5): # new moon outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])]) else : inner_canv.fill(waxing_moon(X, small_moon_rad, x, y), [style.linejoin.bevel,mooncolordark]) # Waning moon (moonrises) moon_rise = obs.next_rising(moon) moon2.compute(moon_rise) X = moon2.moon_phase x, y = to_chart_coord(moon_rise, chart) if (fabs(ephem.next_full_moon(mpc) - mpc) < 0.5 or fabs(ephem.previous_full_moon(mpc) - mpc) < 0.5) : # full moon outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) elif ((X < 0.55 and X > 0.45) or fabs(ephem.next_last_quarter_moon(mpc) - mpc) < 0.5 or fabs(ephem.previous_last_quarter_moon(mpc) - mpc) < 0.5) : # last quarter outer_canv.stroke(last_quarter_moon(large_moon_rad, x,y),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) elif (fabs(ephem.next_new_moon(mpc) - mpc) < 0.5 or fabs(ephem.previous_new_moon(mpc) - mpc) < 0.5): # new moon outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])]) else : inner_canv.fill(waning_moon(X, small_moon_rad, x, y), [style.linejoin.bevel,mooncolorlight])
def draw(dx=0., dy=0., use_arrows=True): r = 4.*m syndrome1 = syndrome.copy() lines = [] for tree in trees: for p0 in tree.sites: x0, y0 = coord(*p0) c.fill(path.circle(x0+dx, y0+dy, r), [grey]) p1 = tree.parent[p0] #print p0, p1 if p1 is None: continue # root lines.append((p0, p1)) x1, y1 = coord(*p1) #syndrome1[p0] = 0 #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy), # [style.linewidth.Thick, deco.earrow(size=0.3)]) if x0==x1: c.fill(path.rect(x0-r+dx, y0+dy, 2*r, y1-y0), [grey]) else: c.fill(path.rect(x0+dx, y0-r+dy, x1-x0, 2*r), [grey]) c.fill(path.circle(x0+dx, y0+dy, r), [grey]) c.fill(path.circle(x1+dx, y1+dy, r), [grey]) #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy), # [style.linewidth.THICK, style.linecap.round, grey]) if use_arrows: t = 0.1 s = 1.-t for (p0, p1) in lines: x0, y0 = coord(*p0) x1, y1 = coord(*p1) #x0, x1 = s*x0+t*x1, s*x1+t*x0 #y0, y1 = s*y0+t*y1, s*y1+t*y0 if syndrome[p1]: x1 = s*x1+t*x0 y1 = s*y1+t*y0 syndrome1[p0] = 0 c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy), [style.linewidth.Thick, style.linecap.round, deco.earrow(size=0.2)]) for i, j in sites: c.stroke(path.rect(j*w+dx, i*h+dy, w-2*m, h-2*m)) if syndrome[i,j]: x, y = coord(i, j) anyon(x+dx, y+dy, 0.1*w) syndrome[:] = syndrome1
def manifold(x, y, labels): global count if count in [0, 2]: c.stroke(path.line(x-r0, y, x+r1+r0, y), st_curve) else: extra = list(st_curve) if count==3: extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1)) Turtle(x-0.85*r0, y, pi/2).\ fwd(0.3).\ right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\ fwd(0.55).\ right(0.88*pi, 0.15).right(0.50*pi, 0.73).left(0.25*pi, 0.4).goto(x+r1+r0, y).\ stroke(extra) # st_target = st_curve+st_dashed st_target = [red, style.linewidth.THick, deco.earrow(size=0.2)] if count == 0: Turtle(x, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*r1).stroke(st_target) elif count == 3: Turtle(x-0.05, y, 0.90*pi).left(0.30*pi, 0.8).left(0.3*pi, 2.8).stroke(st_target) else: Turtle(x+r0, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*(r1-r0)).stroke(st_target) for i in range(3): _x = [x, x+r0, x+r1][i] p = path.circle(_x, y, 0.08) c.fill(p, [white]) c.stroke(p) ydelta = 0.25 xdelta = 0.00 if count==1 and labels[i]=="a": ydelta = -0.35 xdelta = +0.1 if count==3 and labels[i]=="a": ydelta = -0.35 xdelta = -0.1 c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], south) c.text(x+(r0+r1)/2., y-0.2, "...", north) c.stroke(path.circle(x+r0/2, y, r0), [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)]) if count in [0, 3]: c.text(x+r0, y+0.3*h, "$\omega$", southwest) else: c.text(x+r0, y+0.3*h, "$f(\omega)$", southwest) count += 1
def draw_points_to_canvas(c, points: torch.Tensor, size=1, pcols=None): if pcols is not None: pcols = pcols.detach().cpu() if points is not None: points = points.detach().cpu() for i in range(points.shape[0]): _size = size[i] if isinstance(size, torch.Tensor) else size if _size > 0: if pcols is None: c.fill(path.circle(points[i, 1], -points[i, 0], _size)) else: c.fill(path.circle(points[i, 1], -points[i, 0], _size), [color.rgb(*pcols[i])])
def braid_id(x0=0., y0=0., H=3.0, t0="", t1=""): tr = [trafo.translate(x0, y0)] timeslice(x0, y0, 0., t0) for i in range(3): x = i*w c.stroke(path.line(x, 0., x, H), st_Thick+tr) timeslice(x0, y0+H, 0.3, t1) for i in range(3): c.fill(path.circle(i*w, 0., 0.06), tr) c.fill(path.circle(i*w, H, 0.06), tr)
def braid_1(x0=0., y0=0., H=3.0, t0="", t1="", inverse=False): if inverse: rev = lambda x : list(reversed(x)) rev1 = lambda ps : [(x, H-y) for (x, y) in reversed(ps)] else: rev = list rev1 = list tr = [trafo.translate(x0, y0)] ps0 = [] ps1 = [] ps2 = [] for i in range(N+1): r = 1.*i/N y = r*H r1 = bump(r) x = 0.5*(w - w*cos(2*pi*r1)) ps0.append((x, y)) x = w + w*(sin(0.5*pi*r)) ps1.append((x, y)) x = 1*w + w*cos(1.5*pi*r1) ps2.append((x, y)) ps0 = rev1(ps0) ps1 = rev1(ps1) ps2 = rev1(ps2) if not inverse: # HACK timeslice(x0, y0, 0., t0) for ps in draw(ps0, [ps1, ps2], rev([True, False])): dopath(ps, st_Thick+tr) for ps in draw(ps1, [ps0, ps2], rev([False])): dopath(ps, st_Thick+tr) for ps in draw(ps2, [ps0, ps1], rev([True, False, True])): dopath(ps, st_Thick+tr) timeslice(x0, y0+H, 0.3, t1) for i in range(3): c.fill(path.circle(i*w, 0., 0.06), tr) c.fill(path.circle(i*w, H, 0.06), tr)
def __init__(self, diag, px, py, channel, channel_type): Shape.__init__(self, diag, px, py) self.channel = channel self.channel_type = channel_type if channel_type == ChannelType.INPUT: self.outline = cut_hexagon(px, py, self.radius * .8) self.color = ColorScheme.cue elif channel_type == ChannelType.OUTPUT: # self.outline = ppath.circle(px, py, self.radius * .8) self.outline = cut_hexagon_rotated(px, py, self.radius * .8) self.color = ColorScheme.act # self.color = pcolor.gradient.Jet.getcolor(channel * .05) else: self.outline = ppath.circle(px, py, self.radius * .8) # self.outline = diamond(px, py, self.radius) # self.color = pcolor.gradient.WhiteRed.getcolor( # (channel - p.reg_range[0]) * (1.0/p.reg_channels)) # self.color = pcolor.gradient.Gray.getcolor(annote[channel]['W']) self.color = pcolor.cmyk.Black # ColorScheme.sig if channel == diag.highlight: self.color = pcolor.cmyk.Red self.text = latexify(self.diagram.world.name_for_channel(channel))
def mark(self, canv, r=POINT_RADIUS, color=POINT_STD_COLOR): circle = path.circle(self.x, self.y, r) style = [color] if self.name is not None: canv.text(self.x + 10, self.y + 10, self.name, TEXT_DEFAULT_STYLE) canv.fill(circle, style)
def guide_layer(holes): guide_size = 1.2 # Get guide fiber information iguide = np.nonzero(np.array(holes['holetype']) == b'GUIDE')[0] guide_xfocal = np.array(holes['xfocal'])[iguide] guide_yfocal = np.array(holes['yfocal'])[iguide] guidenum = np.array(holes['iguide'])[iguide] # Set up object to print clippath = path.circle(0., 0., interior_radius) clipobject = canvas.clip(clippath) interior = canvas.canvas([clipobject]) for indx in range(len(guide_xfocal)): interior.stroke( path.rect((guide_yfocal[indx] / 10.) - guide_size * 0.5, (guide_xfocal[indx] / 10.) - guide_size * 0.5, guide_size, guide_size), [style.linewidth.THick, color.cmyk.Black]) interior.text( (guide_yfocal[indx] / 10.) + guide_size * 0.66, (guide_xfocal[indx] / 10.), r"\font\myfont=cmr10 at 35pt {\myfont " + str(guidenum[indx]) + "}", [text.halign.boxleft, text.valign.middle, text.size.Huge]) return interior
def draw(self, r=5): c = canvas.canvas() x_centre = r + 1 y_centre = r + 1 angle_diff = 2*math.pi/self.n def get_pos(index): x_pos = x_centre + math.sin(index*angle_diff)*r y_pos = y_centre + math.cos(index*angle_diff)*r return x_pos, y_pos # nodes for i in range(self.n): x, y = get_pos(i) c.stroke(path.circle(x, y, 1)) c.text(x, y, i) # edges for i in range(self.n): for j in range(self.n): if math.isnan(self.adj_mat[i, j]): continue x1, y1 = get_pos(i) x2, y2 = get_pos(j) x_offset = (x2 - x1)/math.sqrt((x1 - x2)**2 + (y1 - y2)**2) y_offset = (y2 - y1)/math.sqrt((x1 - x2)**2 + (y1 - y2)**2) arc = path.line(x1 + x_offset, y1 + y_offset, x2 - x_offset, y2 - y_offset) c.stroke(arc, [deco.earrow()]) c.text((x1 + x2)/2 + x_offset, (y1 + y2)/2 + y_offset, self.adj_mat[i, j]) # moved towards the end pt c.writePDFfile("graph")
def plate_circle_layer(plate, information, message, plate_radius=32.6): outerclip = 39.6 box_xoffset = 1. box_xsize = 4. box_ysize = 16. text_ybuffer = 0.5 text_xbuffer = 0.3 clippath = path.circle(0., 0., outerclip) plate_clipobject = canvas.clip(clippath) plate_circle = canvas.canvas([plate_clipobject]) plate_circle.stroke(path.circle(0., 0., plate_radius), [style.linewidth.THICk]) plate_circle.stroke( path.line(-plate_radius + box_xoffset, -box_ysize * 0.5, -plate_radius + box_xoffset - box_xsize, -box_ysize * 0.5), [style.linewidth.THICk]) plate_circle.stroke( path.line(-plate_radius + box_xoffset - box_xsize, -box_ysize * 0.5, -plate_radius + box_xoffset - box_xsize, box_ysize * 0.5), [style.linewidth.THICk]) plate_circle.stroke( path.line(-plate_radius + box_xoffset, box_ysize * 0.5, -plate_radius + box_xoffset - box_xsize, box_ysize * 0.5), [style.linewidth.THICk]) tab_path = path.line(-plate_radius - text_xbuffer, -box_ysize * 0.5 + text_ybuffer, -plate_radius - text_xbuffer, box_ysize * 0.5 - text_ybuffer) tab_text = r"\font\myfont=cmr10 at 100pt {\myfont " + str(plate) + "}" plate_circle.draw(tab_path, [deco.curvedtext(tab_text)]) information_path = (path.circle(0., 0., plate_radius).transformed( trafo.rotate(90.))) plate_circle.draw(information_path, [ deco.curvedtext(information, textattrs=[text.valign.top, text.vshift.topzero]) ]) message_path = (path.circle(0., 0., plate_radius).transformed(trafo.rotate(-90.))) plate_circle.draw(message_path, [ deco.curvedtext(message, textattrs=[text.valign.top, text.vshift.topzero]) ]) return plate_circle
def draw_drop(x, y, r, c): c.fill(path.circle(x, y - 3 * r, r), [color.cmyk.RoyalBlue]) c.stroke(path.circle(x, y - 3 * r, r)) triangle = path.line( x, y, x + sqrt(8) * r / 3, y - 8 * r / 3) << path.line( x + sqrt(8) * r / 3, y - 8 * r / 3, x - sqrt(8) * r / 3, y - 8 * r / 3) triangle.append(path.closepath()) c.fill(triangle, [color.cmyk.RoyalBlue]) c.stroke( path.line(x - sqrt(8) * r / 3, y - 8 * r / 3, x, y) << path.line(x, y, x + sqrt(8) * r / 3, y - 8 * r / 3)) c.fill(path.circle(x - 0.5 * r, (y - 3 * r) / 2, 0.2 * r), [color.rgb.white, trafo.scale(sx=1, sy=2)])
def ellipse(x, y, radius, sx=1., sy=1., color=None, extra=[], arrow=None): p = path.circle(x, y, radius) t = trafo.scale(sx=sx, sy=sy) if color: c.fill(p, [t, shade]+extra) c.stroke(p, [t]+extra) if arrow is not None: c.stroke(p, [t]+extra+[deco.earrow(size=arrow)])
def hole(x, y, radius, msg=None, extra=[], arrow=None): p = path.circle(x, y, radius) c.fill(p, [white]+extra) c.stroke(p, extra) if arrow is not None: c.stroke(p, extra+[deco.earrow(size=arrow)]) if msg: c.text(x, y, msg, [text.halign.boxcenter, text.valign.middle])
def draw(self): """draw the text!!""" for layer in self.sectors: radius = self.sectors[layer]['radius'] letter_radius = radius + 0.25 * self.sector_width prev_radian = 0 for radian in self.sectors[layer]['letters']: end = False letter = self.sectors[layer]['letters'][radian][0] if len(letter) > 1: end = True freq = self.sectors[layer]['letters'][radian][1] offset = False cur_radian = radian if (radian - prev_radian) * letter_radius < 0.22: cur_radian = prev_radian + 0.22 / letter_radius prev_radian = cur_radian offset = True centroid_x = radius * cos(radian) + self.xo centroid_y = radius * sin(radian) + self.yo if end: letter_x = radius * cos(cur_radian) + self.xo letter_y = radius * sin(cur_radian) + self.yo else: letter_x = letter_radius * cos(cur_radian) + self.xo letter_y = letter_radius * sin(cur_radian) + self.yo # rotate the text accordingly transform = trafo.rotate(radian * 180 / pi) if cur_radian > pi / 2 and cur_radian < (3 * pi / 2): transform = trafo.rotate(180 + radian * 180 / pi) # if this condition is true then the letter is actually the # whole word, it is an end sector, so display the frequency if len(letter) > 1: letter += ' ' letter += str(freq) # the random floats are me tuning the color just right lol text_color = color.rgb(0, 0.0784 * 1.4, 0.156 * 1.4) self.canvas.text( letter_x, letter_y, r"\texttt{" + letter + '}', [ text.halign.center, text.valign.middle, transform, text.size.scriptsize, text_color ]) if offset: self.canvas.stroke( path.line(centroid_x, centroid_y, letter_x, letter_y), [style.linewidth(0.0035), text_color]) self.canvas.fill(path.circle(centroid_x, centroid_y, 0.0065), [text_color]) prev_radian = cur_radian
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 slice(x, y): p = path.circle(x, y, 1.) t = trafo.scale(1., 0.3, x, y) c.fill(p, [shade, t]) c.stroke(p, [t]) hole(x-0.5, y, 0.07, '') hole(x, y, 0.07, '') hole(x+0.5, y, 0.07, '')
def showp(gx, radius): v = dot2(gx, PxtQx) syndrome = dot2(GzRxt, v) x = gz - 2*syndrome.sum() i = lookup[v.tobytes()] #print syndrome, syndrome.sum(), vec0[i] y = (1./my)*yfunc(vec0[i]) + 0.5*dy #y = 0.5*dy + log2(abs(vec0[i])) c.fill(path.circle(-x*sx, y*sy, radius), [lgrey])
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 _draw_linear_lattice(self,loc,w,n,key=None,energy=None,degeneracy=None): x,y = loc sx,sy = w,n*w x0,x1 = x-(sx/2.0),x+(sx/2.0) y0,y1 = y-(sy/2.0),y+(sy/2.0) rect = box.polygon([(x0, y0),(x1, y0),(x1, y1),(x0, y1)]) c.stroke(rect.path(), [style.linewidth.Thick]) # deformer.smoothed(radius=w*2)]) for i in range(0,n): if key[i] > 0: c.fill(path.circle(x,y+(i*w)-(sy/2.0)+(w/2.0),w*0.3), [color.rgb.blue]) c.stroke(path.circle(x,y+(i*w)-(sy/2.0)+(w/2.0),w*0.4), [style.linewidth.Thick]) c.text(x+(w*0.6),y+(0.4*sy), dG_format%(energy), [text.halign.boxleft, text.valign.middle] ) if degeneracy != None: t = c.text(x+(w*0.6),y-(0.4*sy), r"x%s"%str(degeneracy), [text.halign.boxleft, text.valign.top])
def make_dirs_plot(filename, dirs_dict, other=None): plot_canvas = canvas.canvas() plot_canvas.stroke(path.circle(0, 0, 10)) for sample_name in dirs_dict.keys(): if other is None: dirs_dict[sample_name].plot(plot_canvas) else: dirs_dict[sample_name].plot(plot_canvas, other=other[sample_name]) plot_canvas.writePDFfile(filename)
def _draw_linear_lattice(self,loc,w,n,key=None,energy=None,degeneracy=None): x,y = loc sx,sy = w,n*w x0,x1 = x-(sx/2.0),x+(sx/2.0) y0,y1 = y-(sy/2.0),y+(sy/2.0) rect = box.polygon([(x0, y0),(x1, y0),(x1, y1),(x0, y1)]) c.stroke(rect.path(), [style.linewidth.Thick]) # deformer.smoothed(radius=w*2)]) for i in xrange(0,n): if key[i] > 0: c.fill(path.circle(x,y+(i*w)-(sy/2.0)+(w/2.0),w*0.3), [color.rgb.blue]) c.stroke(path.circle(x,y+(i*w)-(sy/2.0)+(w/2.0),w*0.4), [style.linewidth.Thick]) texrun = text.defaulttexrunner c.insert(texrun.text(x+(w*0.6),y+(0.4*sy), dG_format%(energy), [text.halign.boxleft, text.valign.middle] )) if degeneracy != None: t = c.text(x+(w*0.6),y-(0.4*sy), r"x%s"%str(degeneracy), [text.halign.boxleft, text.valign.top])
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
def tree(x, y, dx, dy, branches, leaves, braid=False, braid2=False, clr=None): for i, leaf in enumerate(leaves): if leaf: c.text(x + i*dx, y+pip, leaf, [text.halign.boxcenter]) ldeco = [style.linewidth.Thick, clr or blue] if braid: a = 0.4 c.stroke(path.line(x, y, x+a*dx, y-a*2*dy), ldeco) b = 0.6 c.stroke(path.line(x+b*dx, y-b*2*dy, x+dx, y-2*dy), ldeco) c.stroke(path.line(x+dx, y, x, y-2*dy), ldeco) y -= 2*dy if braid2: col = lred c.stroke(path.line(x+3*dx, y, x+2*dx, y-2*dy), ldeco) c.fill(path.circle(x+2.5*dx, y-1*dy, pip), [color.rgb.white]) c.stroke(path.line(x+4*dx, y, x+3*dx, y-2*dy), ldeco) c.fill(path.circle(x+3.25*dx, y-1.45*dy, pip), [color.rgb.white]) c.stroke(path.line(x+1*dx, y, x+4*dx, y-2*dy), ldeco) c.fill(path.circle(x+1.75*dx, y-0.45*dy, pip), [color.rgb.white]) c.stroke(path.line(x+2*dx, y, x+1*dx, y-2*dy), ldeco) c.stroke(path.line(x, y, x, y-2*dy), ldeco) c.stroke(path.line(x+5*dx, y, x+5*dx, y-2*dy), ldeco) y -= 2*dy for branch in branches: row, col, lr = branch[:3] x0 = x + col*dx + 0.5*row*dx + lr*dx x1 = x + col*dx + 0.5*row*dx + 0.5*dx y0 = y -row*dy y1 = y -(row+1)*dy c.stroke(path.line(x0, y0, x1, y1), ldeco) if len(branch)==4: extra = [text.valign.top] extra += [text.halign.boxleft] if lr else [text.halign.boxright] c.text(x1, y1-pip, branch[3], extra)
def draw(dx=0., dy=0.): r = 4.*m data1 = data.copy() lines = [] for tree in trees: for p0 in tree.sites: x0, y0 = coord(*p0) c.fill(path.circle(x0+dx, y0+dy, r), [grey]) p1 = tree.parent[p0] #print p0, p1 if p1 is None: continue # root lines.append((p0, p1)) x1, y1 = coord(*p1) #data1[p0] = 0 #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy), # [style.linewidth.Thick, deco.earrow(size=0.3)]) if x0==x1: c.fill(path.rect(x0-r+dx, y0+dy, 2*r, y1-y0), [grey]) else: c.fill(path.rect(x0+dx, y0-r+dy, x1-x0, 2*r), [grey]) c.fill(path.circle(x0+dx, y0+dy, r), [grey]) c.fill(path.circle(x1+dx, y1+dy, r), [grey]) #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy), # [style.linewidth.THICK, style.linecap.round, grey]) for (p0, p1) in lines: x0, y0 = coord(*p0) x1, y1 = coord(*p1) data1[p0] = 0 c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy), [style.linewidth.Thick, deco.earrow(size=0.3)]) for i, j in sites: c.stroke(path.rect(j*w+dx, i*h+dy, w-2*m, h-2*m)) if data[i,j]: x, y = coord(i, j) anyon(x+dx, y+dy, 0.1*w) data[:] = data1
def outline_layer(): tab_xsize = 1.3 tab_ysize = 2.0 clippath = path.circle(0., 0., limit_radius) clipobject = canvas.clip(clippath) outline = canvas.canvas([clipobject]) outline.stroke(path.circle(0., 0., full_radius), [style.linewidth.thick]) outline.stroke( path.line(-full_radius, -tab_ysize * 0.5, -full_radius - tab_xsize, -tab_ysize * 0.5), [style.linewidth.thick]) outline.stroke( path.line(-full_radius, tab_ysize * 0.5, -full_radius - tab_xsize, tab_ysize * 0.5), [style.linewidth.thick]) outline.stroke( path.line(-full_radius - tab_xsize, -tab_ysize * 0.5, -full_radius - tab_xsize, tab_ysize * 0.5), [style.linewidth.thick]) outline.stroke(path.line(-full_radius - tab_xsize, 0., -limit_radius, 0.), [style.linewidth.thick]) return outline
def manifold(x, y, labels): global count p = path.circle(x+r0/2, y, r0) extra = [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)] c.fill(p, extra+[shade]) c.stroke(p, extra) if count in [0, 2]: c.stroke(path.line(x-0.5*r0, y, x+r0+0.5*r0, y), st_curve) else: extra = list(st_curve) if count==3: extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1)) Turtle(x-0.85*r0+0.3, y, pi/2).\ right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\ fwd(0.55).\ right(0.88*pi, 0.15).right(0.50*pi, 0.73).left(0.25*pi, 0.4).\ stroke(extra) for i in range(2): _x = [x, x+r0][i] p = path.circle(_x, y, 0.08) c.fill(p, [white]) c.stroke(p) ydelta = 0.25 xdelta = 0.00 if count==1 and labels[i]=="a": ydelta = -0.35 xdelta = +0.1 if count==3 and labels[i]=="a": ydelta = -0.35 xdelta = -0.1 c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], south) c.text(x+1.5*r0, y-0.6, r"$\scriptstyle \hat{c}$", center) c.text(x+1.7*r0, y, r"$\bigr)$", center) c.text(x-0.9*r0, y, r"$\H\bigl($", center) count += 1
def make_moon_key(canv, chart) : large_moon_rad = 0.16 small_moon_rad = 0.12 x = 0.0 y = -1.8 canv.fill(path.rect(x, y, chart.width, 1.0), [color.rgb(0.0, 0.0, 0.0)]) for i in range(8) : X = 1.0-(i+1.0)/9.0 canv.fill(waning_moon(X, small_moon_rad, x+(i+4.0)/4.0, -1.3), [style.linejoin.bevel,mooncolorlight]) canv.text(x+1.8, -1.1, r'{\footnotesize\sffamily Küçülen Ay}', [text.halign.center,text.valign.baseline,mooncolorlight]) canv.text(x+1.8, -1.7, r"{\scriptsize\sffamily (Ay'ın doğuş zamanları)}", [text.halign.center,text.valign.baseline,mooncolorlight]) for i in range(8) : X = (i+1.0)/9.0 canv.fill(waxing_moon(X, small_moon_rad, x+(i+4.0)/4.0+3.0, -1.3), [style.linejoin.bevel,mooncolordark]) canv.text(x+1.8+3.0, -1.1, r'{\footnotesize\sffamily Büyüyen Ay}', [text.halign.center,text.valign.baseline,mooncolordark]) canv.text(x+1.8+3.0, -1.7, r"{\scriptsize\sffamily (Ay'ın batış zamanları)}", [text.halign.center,text.valign.baseline,mooncolordark]) # new moon, first quarter # full moon, last quarter canv.stroke(path.circle(x+8.5,-1.1,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])]) canv.text(x+8.25, -1.2, r'{\footnotesize\sffamily Yeni ay}', [text.halign.right,text.valign.baseline, mooncolordark]) canv.stroke(first_quarter_moon(large_moon_rad, x+8.9,-1.1),[mooncolordark,pyx.deco.filled([mooncolordark])]) canv.text(x+9.25, -1.2, r'{\footnotesize\sffamily İlk dördün}', [text.halign.left,text.valign.baseline, mooncolordark]) canv.stroke(path.circle(x+8.5,-1.5,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) canv.text(x+8.25, -1.6, r'{\footnotesize\sffamily Dolunay}', [text.halign.right,text.valign.baseline, mooncolorlight]) canv.stroke(last_quarter_moon(large_moon_rad, x+8.9,-1.5),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) canv.text(x+9.25, -1.6, r'{\footnotesize\sffamily Son dördün}', [text.halign.left,text.valign.baseline, mooncolorlight])
def _draw_circular_lattice(self,loc,r,n,key=None,energy=None,degeneracy=None): x,y = loc chord = 2.0*r*scipy.sin(scipy.pi/n) site_r = (r-(chord/2.0))*scipy.sin(scipy.pi/n) outer_r = site_r / scipy.sin(scipy.pi/n) + site_r inner_r = site_r / scipy.sin(scipy.pi/n) - site_r c.stroke(path.circle(x,y,outer_r), [style.linewidth.Thick]) c.stroke(path.circle(x,y,inner_r), [style.linewidth.Thick]) c.text(x, y, dG_format%(energy), [text.halign.boxcenter, text.valign.middle] ) if degeneracy != None: t = c.text(x+(r*0.68),y-(r*0.68), r"x%s"%str(degeneracy), [text.halign.boxleft, text.valign.top]) for i in range(0,n): circ_x = x+(scipy.cos(2.0*scipy.pi/n*i)*(r-(0.5*chord))) circ_y = y+(scipy.sin(2.0*scipy.pi/n*i)*(r-(0.5*chord))) if key[i] > 0: c.fill(path.circle(circ_x,circ_y,site_r*0.6), [color.rgb.blue]) c.stroke(path.circle(circ_x,circ_y,site_r*0.8), [style.linewidth.Thick])
def draw_points(points: torch.Tensor, filename, size=1, svg=False): c = canvas.canvas() points = points.detach().cpu() for i in range(points.shape[0]): c.fill(path.circle(points[i, 1], -points[i, 0], size)) if svg: c.writeSVGfile(file=filename) else: c.writePDFfile(file=filename)
def _draw_circular_lattice(self,loc,r,n,key=None,energy=None,degeneracy=None): x,y = loc chord = 2.0*r*scipy.sin(scipy.pi/n) site_r = (r-(chord/2.0))*scipy.sin(scipy.pi/n) outer_r = site_r / scipy.sin(scipy.pi/n) + site_r inner_r = site_r / scipy.sin(scipy.pi/n) - site_r c.stroke(path.circle(x,y,outer_r), [style.linewidth.Thick]) c.stroke(path.circle(x,y,inner_r), [style.linewidth.Thick]) texrun = text.defaulttexrunner c.insert(texrun.text(x, y, dG_format%(energy), [text.halign.boxcenter, text.valign.middle] )) if degeneracy != None: t = c.text(x+(r*0.68),y-(r*0.68), r"x%s"%str(degeneracy), [text.halign.boxleft, text.valign.top]) for i in xrange(0,n): circ_x = x+(scipy.cos(2.0*scipy.pi/n*i)*(r-(0.5*chord))) circ_y = y+(scipy.sin(2.0*scipy.pi/n*i)*(r-(0.5*chord))) if key[i] > 0: c.fill(path.circle(circ_x,circ_y,site_r*0.6), [color.rgb.blue]) c.stroke(path.circle(circ_x,circ_y,site_r*0.8), [style.linewidth.Thick])
def make_moon_key2(canv, chart, y) : x = 0.0 canv.fill(path.rect(x, y, chart.width-1.0, 1.0), [color.rgb(0.0, 0.0, 0.0)]) for i in range(8) : X = 1.0-(i+1.0)/9.0 canv.fill(waning_moon(X, 0.08, x+(i+4.0)/4.0, y+0.5), [style.linejoin.bevel,mooncolorlight]) canv.text(x+1.8, y+0.7, r'{\footnotesize\sffamily Küçülen Ay}', [text.halign.center,text.valign.baseline,mooncolorlight]) canv.text(x+1.8, y+0.2, r"{\scriptsize\sffamily (Ay'ın doğuş zamanları)}", [text.halign.center,text.valign.baseline,mooncolorlight]) for i in range(8) : X = (i+1.0)/9.0 canv.fill(waxing_moon(X, 0.08, x+(i+4.0)/4.0+3.0, y+0.5), [style.linejoin.bevel,mooncolordark]) canv.text(x+1.8+3.0, y+0.7, r'{\footnotesize\sffamily Büyüyen Ay}', [text.halign.center,text.valign.baseline,mooncolordark]) canv.text(x+1.8+3.0, y+0.2, r"{\scriptsize\sffamily (Ay'ın batış zamanları)}", [text.halign.center,text.valign.baseline,mooncolordark]) # new moon, first quarter # full moon, last quarter canv.stroke(path.circle(x+8.5,y+0.7,.12),[mooncolorlight,pyx.deco.filled([mooncolordark])]) canv.text(x+8.25, y+0.6, r'{\footnotesize\sffamily Yeni Ay}', [text.halign.right,text.valign.baseline, mooncolordark]) canv.stroke(first_quarter_moon(0.12, x+8.9,y+0.7),[mooncolordark,pyx.deco.filled([mooncolordark])]) canv.text(x+9.25, y+0.6, r'{\footnotesize\sffamily İlk Dördün}', [text.halign.left,text.valign.baseline, mooncolordark]) canv.stroke(path.circle(x+8.5,y+0.3,.12),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) canv.text(x+8.25, y+0.2, r'{\footnotesize\sffamily Dolunay}', [text.halign.right,text.valign.baseline, mooncolorlight]) canv.stroke(last_quarter_moon(0.12, x+8.9,y+0.3),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) canv.text(x+9.25, y+0.2, r'{\footnotesize\sffamily Son Dördün}', [text.halign.left,text.valign.baseline, mooncolorlight])
def make_moon_key2_eng(canv, chart, y) : x = 0.0 canv.fill(path.rect(x, y, chart.width, 1.0), [color.rgb(0.0, 0.0, 0.0)]) for i in range(8) : X = 1.0-(i+1.0)/9.0 canv.fill(waning_moon(X, 0.08, x+(i+4.0)/4.0, y+0.5), [style.linejoin.bevel,mooncolorlight]) canv.text(x+1.8, y+0.7, r'{\footnotesize\sffamily Waning Moon}', [text.halign.center,text.valign.baseline,mooncolorlight]) canv.text(x+1.8, y+0.2, r"{\scriptsize\sffamily (Moon rising)}", [text.halign.center,text.valign.baseline,mooncolorlight]) for i in range(8) : X = (i+1.0)/9.0 canv.fill(waxing_moon(X, 0.08, x+(i+4.0)/4.0+3.0, y+0.5), [style.linejoin.bevel,mooncolordark]) canv.text(x+1.8+3.0, y+0.7, r'{\footnotesize\sffamily Waxing Moon}', [text.halign.center,text.valign.baseline,mooncolordark]) canv.text(x+1.8+3.0, y+0.2, r"{\scriptsize\sffamily (Moon setting)}", [text.halign.center,text.valign.baseline,mooncolordark]) # new moon, first quarter # full moon, last quarter canv.stroke(path.circle(x+8.5,y+0.75,.12),[mooncolorlight,pyx.deco.filled([mooncolordark])]) canv.text(x+8.25, y+0.65, r'{\footnotesize\sffamily New Moon}', [text.halign.right,text.valign.baseline, mooncolordark]) canv.stroke(first_quarter_moon(0.12, x+8.9,y+0.75),[mooncolordark,pyx.deco.filled([mooncolordark])]) canv.text(x+9.25, y+0.65, r'{\footnotesize\sffamily First Quarter}', [text.halign.left,text.valign.baseline, mooncolordark]) canv.stroke(path.circle(x+8.5,y+0.35,.12),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) canv.text(x+8.25, y+0.25, r'{\footnotesize\sffamily Full Moon}', [text.halign.right,text.valign.baseline, mooncolorlight]) canv.stroke(last_quarter_moon(0.12, x+8.9,y+0.35),[mooncolorlight,pyx.deco.filled([mooncolorlight])]) canv.text(x+9.25, y+0.25, r'{\footnotesize\sffamily Last Quarter}', [text.halign.left,text.valign.baseline, mooncolorlight])
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 acquisition_layer(holes): # Get camera info icenter = np.nonzero( np.array(holes['holetype']) == b'ACQUISITION_CENTER')[0] if (len(icenter) == 0): return None if (len(icenter) > 1): print("Expect just one central acquisition camera.") center_xfocal = np.array(holes['xfocal'])[icenter[0]] center_yfocal = np.array(holes['yfocal'])[icenter[0]] ioffaxis = np.nonzero( np.array(holes['holetype']) == b'ACQUISITION_OFFAXIS')[0] if (len(ioffaxis) == 0): print("If there is a center acquisition camera we expect an off-axis.") sys.exit() if (len(ioffaxis) > 1): print("Expect just one off-axis acquisition camera.") sys.exit() offaxis_xfocal = np.array(holes['xfocal'])[ioffaxis[0]] offaxis_yfocal = np.array(holes['yfocal'])[ioffaxis[0]] # Set up object to print clippath = path.circle(0., 0., interior_radius) clipobject = canvas.clip(clippath) interior = canvas.canvas([clipobject]) interior.stroke( path.circle(center_yfocal / 10., center_xfocal / 10., center_radius), [style.linewidth.THick, color.cmyk.Black]) interior.stroke( path.rect((offaxis_yfocal / 10.) - offaxis_ysize * 0.5, (offaxis_xfocal / 10.) - offaxis_xsize * 0.5, offaxis_ysize, offaxis_xsize), [style.linewidth.THick, color.cmyk.Black]) return interior
def cluster_sunburst(organism, graph, method): c = canvas.canvas() core_length = 5 recurse_sunburst(c, graph, core_length, 0, 360) core = path.circle(0, 0, core_length) c.stroke(core, [ style.linewidth(0.1), pyx.color.rgb(1, 1, 1), deco.filled([pyx.color.rgb(1, 1, 1)]) ]) file_name = '{}-{}-clusters_sunburst.svg'.format(organism.org_id, method) with open(utils.join_path(cs.SVG_PATH, file_name), 'wb') as svg: c.writeSVGfile(svg)
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 draw_graph(graph, pts=None, name="output"): import pyx from pyx import path, deco, trafo, style, text, color, deformer from pyx.color import rgb, cmyk from pyx.color import rgbfromhexstring as rgbhex black = rgb(0., 0., 0.) blue = rgb(0., 0., 0.8) lred = rgb(1., 0.4, 0.4) red = rgb(1., 0.0, 0.0) white = rgb(1., 1., 1.) if pts is None: pts = pos_circ(graph) directed = isinstance(graph, (nx.DiGraph, nx.MultiDiGraph)) #W = 10. #H = 10. R = 1.5 r = 0.2 c = pyx.canvas.canvas() for edge in graph.edges(): src, tgt = edge x0, y0 = pts[src] x1, y1 = pts[tgt] color = black if edge in edge_colors: color = eval(edge_colors[edge]) c.stroke(path.line(R * x0, R * y0, R * x1, R * y1), [color]) for node in graph.nodes(): x, y = pts[node] p = path.circle(R * x, R * y, r) color = white if node in node_colors: color = eval(node_colors[node]) c.fill(p, [color]) c.stroke(p, [black]) c.writePDFfile(name)
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))
def whiteout_layer(holes): whiteout = canvas.canvas() for indx in range(len(holes['xfocal'])): radius = 0.25 if (holes['holetype'][indx] == b'GUIDE'): radius = 0.54 if (holes['holetype'][indx] == b'ALIGNMENT'): radius = 0.1 if (holes['holetype'][indx] == b'MANGA'): radius = 0.4 if (holes['holetype'][indx] == b'MANGA_SINGLE'): radius = 0.4 if (holes['holetype'][indx] == b'MANGA_ALIGNMENT'): radius = 0.2 if (holes['holetype'][indx] == b'CENTER'): radius = 0.36 if (holes['holetype'][indx] == b'TRAP'): radius = 0.45 if (holes['holetype'][indx] == b'ACQUISITION_CENTER'): radius = 2.9 whiteout.fill( path.circle(holes['yfocal'][indx] / 10., holes['xfocal'][indx] / 10., radius), [color.rgb.white]) ioffaxis = np.nonzero( np.array(holes['holetype']) == b'ACQUISITION_OFFAXIS')[0] if (len(ioffaxis) == 0): return whiteout if (len(ioffaxis) > 1): print("Expect just one off-axis acquisition camera.") sys.exit() offaxis_xfocal = np.array(holes['xfocal'])[ioffaxis[0]] offaxis_yfocal = np.array(holes['yfocal'])[ioffaxis[0]] whiteout.fill( path.rect((offaxis_yfocal / 10.) - offaxis_ysize * 0.49, (offaxis_xfocal / 10.) - offaxis_xsize * 0.49, 0.98 * offaxis_ysize, 0.98 * offaxis_xsize), [color.rgb.white]) return whiteout
def winding(n, radius, angle=60, windingnumber=False, endpointcolor=color.rgb(0.6, 0.2, 0), pathcolor=color.rgb(0.4, 0.3, 0.8)): c = canvas.canvas() ticklen = 0.1 c.stroke(path.circle(0, 0, radius), [style.linewidth.Thin]) tick = path.line((1 - ticklen) * radius, 0, (1 + ticklen) * radius, 0) c.stroke(tick, [endpointcolor, style.linewidth.Thick]) c.stroke(tick, [trafo.rotate(angle), endpointcolor, style.linewidth.Thick]) tick_outer = (1 + ticklen) * radius for _angle, label in ((0, r'$\phi_\text{i}$'), (radians(angle), r'$\phi_\text{f}$')): c.text((tick_outer + 0.3) * cos(_angle), (tick_outer + 0.3) * sin(_angle), label, [text.halign.center, text.valign.middle, endpointcolor]) if windingnumber: c.text(0, -radius - 0.3, '$n={}$'.format(n), [text.halign.center, text.valign.top]) c.stroke(spiral(radius, angle, n), [pathcolor, style.linewidth.Thick]) return c
punkte = 1 nrboxes = 3 nrpoints = 3 ldist = 0.05 boxcolor = color.rgb(1, 0.7, 0.4) c.fill(path.rect(-0.3 * dist, -0.2, 7 * kante + 6.6 * dist, kante + 0.4), [boxcolor]) for n in range(nrboxes): x = n * (kante + dist) draw_square(x, 0, kante) c.text(x + ldist * kante, (1 - ldist) * kante, n, [text.valign.top]) nstr = "" if n > 0: nstr = "%+i" % n c.text(x + (1 - 0.5 * ldist) * kante, ldist * kante, '-N' + nstr, [text.halign.right]) x = (n + nrboxes) * (kante + dist) + dist + punkte draw_square(x, 0, kante) c.text(x + ldist * kante, (1 - ldist) * kante, 'N' + str(n - 3), [text.valign.top]) c.text(x + (1 - 0.5 * ldist) * kante, ldist * kante, str(n - 3), [text.halign.right]) xoffset = nrboxes * (kante + dist) for n in range(nrpoints): c.fill( path.circle(xoffset + (0.5 + n) * punkte / nrpoints, 0.5 * kante, 0.05 * kante)) c.writePDFfile()
from pyx import canvas, path, deco, style, color, text from math import sqrt text.set(text.LatexRunner) c = canvas.canvas() c.stroke(path.circle(0, 0, 1)) c.stroke(path.circle(5, 0, 1)) c.stroke(path.circle(15, 0, 1)) c.stroke(path.circle(20, 5, 1)) c.stroke(path.circle(9, 0, 0.1), [style.linewidth.THICK]) c.stroke(path.circle(10, 0, 0.1), [style.linewidth.THICK]) c.stroke(path.circle(11, 0, 0.1), [style.linewidth.THICK]) c.text(0, 0, r'\Huge{1}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(5, 0, r'\Huge{2}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(15, 0, r'\Huge{K}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(20, 5, r'\Huge{0}', [text.parbox(0), text.valign.middle, text.halign.center]) c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 2, 2, 3, 2, 5 - 1 / sqrt(2), 1 / sqrt(2)), [deco.earrow(size=1)]) c.stroke(path.curve(5 - 1 / sqrt(2), -1 / sqrt(2), 3, -2, 2, -2, 1 / sqrt(2), -1 / sqrt(2)), [deco.earrow(size=1)]) c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 1, 5, 10, 5, 19, 5), [deco.earrow(size=1)]) c.stroke(path.curve(5 + 1 / sqrt(2), 1 / sqrt(2), 7, 5, 12, 5, 19, 5), [deco.earrow(size=1)]) c.stroke(path.line(15 + 1 / sqrt(2), 1 / sqrt(2), 20 - 1 / sqrt(2), 5 - 1 / sqrt(2)), [deco.earrow(size=1)]) c.text(2.5, 2.5, r'\huge{$p_1^2$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(2.5, -1, r'\huge{$p_2^1$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(2.5, 4, r'\huge{$p_1^0$}', [text.parbox(0), text.valign.middle, text.halign.center]) c.text(8, 3, r'\huge{$p_2^0$}', [text.parbox(0), text.valign.middle, text.halign.center])
def ellipse(r, scaley, fillcolor): ce = canvas.canvas() ce.fill(path.circle(0, 0, r), [trafo.scale(1, scaley), fillcolor]) return ce
def anyon(x, y, r=0.07): c.fill(path.circle(x, y, r), [white]) c.stroke(path.circle(x, y, r), [style.linewidth.thick])
def bubble(st_1, st_2, st_3): c.stroke(path.line(x, y-3*r, x, y-r), st_1) c.stroke(path.circle(x, y, r), st_2) c.stroke(path.line(x, y+3*r, x, y+r), st_3)
def circle(x, y, r, shade, deco=[], mark=False): p = path.circle(x, y, r) c.fill(p, [shade]) c.stroke(p, deco) if mark: c.fill(path.circle(x, y-r, 0.05))
dx, dy = 1.5, 1.5 # Grid for i in range(3): c.stroke(path.line(x0+0.5*dx, y0-(i+1.0)*dy, x0+3.5*dx, y0-(i+1.0)*dy)) c.stroke(path.line(x0+(i+1.0)*dx, y0-0.5*dy, x0+(i+1.0)*dx, y0-3.5*dy)) c.stroke(path.rect(1.*dx + pip, -2.*dy + pip, dx-2*pip, dy-2*pip), [green, style.linewidth.Thick, style.linestyle.dashed, trafo.translate(tx0, ty0)]) def pair((x0, y0), (x1, y1), clr=None): extra = [clr or blue, style.linewidth.Thick, style.linecap.round, trafo.translate(tx0, ty0)] c.stroke(path.line(x0, y0, x1, y1), extra) c.stroke(path.circle(x0, y0, 1.3*pip), extra) c.stroke(path.circle(x1, y1, 1.3*pip), extra) points0 = [ (1.3*dx, -1.7*dy), (1.3*dx, -2.5*dy), (2.6*dx, -1.4*dy), (3.4*dx, -1.4*dy), (1.7*dx, -1.7*dy), (1.7*dx, -2.5*dy)] points = list(points0) 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
from pyx import canvas, color, deco, 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.4, wscale=1.2) c = canvas.canvas() r = 0.05 for n in range(1, 5): c.stroke(path.circle(n, 0, r)) c.stroke(path.circle(-n, 0, r)) c.stroke(path.circle(0, 0, r), [deco.filled([color.grey(0)])]) dx = 0.1 dy = 0.3 c.stroke(path.curve(dx, dx, dy, dy, 1-dy, dy, 1-dx, dx), [deco.earrow]) c.text(0.5, dy+0.1, '+1', [text.halign.center]) c.stroke(path.curve(-dx, dx, -dy, dy, -1+dy, dy, -1+dx, dx), [deco.earrow]) c.text(-0.5, dy+0.1, '-1', [text.halign.center]) c.writePDFfile()
c.stroke(path.path(path.arc(x+0.0*w, y+0.5*h, 0.2*w, -90, 90)), st_tau) c.stroke(path.path(path.arc(x+1.0*w, y+0.5*h, 0.2*w, 90, -90)), st_tau) c.stroke(path.line(x+0.2*w, y+0.5*h, x+0.8*w, y+0.5*h), st_tau) y -= 1.2*h x = 1.1*w c.text(x, y+0.5*h, r"$= \phi^{-1}$", west) x += 0.7*w frame() #c.stroke(path.line(x+0.5*w, y+0.2*h, x+0.8*w, y+0.5*h), st_tau) #c.stroke(path.line(x+0.5*w, y+0.8*h, x+0.8*w, y+0.5*h), st_tau) #c.stroke(path.line(x+0.5*w, y+0.2*h, x+0.2*w, y+0.5*h), st_tau) #c.stroke(path.line(x+0.5*w, y+0.8*h, x+0.2*w, y+0.5*h), st_tau) c.stroke(path.circle(x+0.5*w, y+0.5*h, 0.2*w), st_tau) c.stroke(path.line(x+0.0*w, y+0.5*h, x+0.3*w, y+0.5*h), st_vac) c.stroke(path.line(x+0.7*w, y+0.5*h, x+1.0*w, y+0.5*h), st_vac) x += 1.1*w c.text(x, y+0.5*h, r"$+ \phi^{-\frac{1}{2}}$", west) x += 0.7*w frame() #c.stroke(path.line(x+0.5*w, y+0.2*h, x+0.8*w, y+0.5*h), st_tau) #c.stroke(path.line(x+0.5*w, y+0.8*h, x+0.8*w, y+0.5*h), st_tau) #c.stroke(path.line(x+0.5*w, y+0.2*h, x+0.2*w, y+0.5*h), st_tau) #c.stroke(path.line(x+0.5*w, y+0.8*h, x+0.2*w, y+0.5*h), st_tau) c.stroke(path.circle(x+0.5*w, y+0.5*h, 0.2*w), st_tau)