def nu1_mu_portrait(n): """ returns an encoded scatter plot of the nth roots of unity in the complex plane """ if n == 1: return db.gps_sato_tate.lookup('1.2.1.2.1a').get('trace_histogram') if n <= 120: plot = sum([line2d([(-2*cos(2*pi*m/n),-2*sin(2*pi*m/n)),(2*cos(2*pi*m/n),2*sin(2*pi*m/n))],thickness=3) for m in range(n)]) + circle((0,0),0.1,rgbcolor=(0,0,0),fill=True) else: plot = circle((0,0),2,fill=True) plot.xmin(-2); plot.xmax(2); plot.ymin(-2); plot.ymax(2) plot.set_aspect_ratio(4.0/3.0) plot.axes(False) return encode_plot(plot)
def nu1_mu_portrait(n): """ returns an encoded scatter plot of the nth roots of unity in the complex plane """ if n == 1: return db.gps_st.lookup('1.2.B.2.1a').get('trace_histogram') if n <= 120: plot = sum([line2d([(-2*cos(2*pi*m/n),-2*sin(2*pi*m/n)),(2*cos(2*pi*m/n),2*sin(2*pi*m/n))],thickness=3) for m in range(n)]) + circle((0,0),0.1,rgbcolor=(0,0,0),fill=True) else: plot = circle((0,0),2,fill=True) plot.xmin(-2); plot.xmax(2); plot.ymin(-2); plot.ymax(2) plot.set_aspect_ratio(4.0/3.0) plot.axes(False) return encode_plot(plot)
def su2_mu_portrait(n): """ returns an encoded line plot of SU(2) x mu(n) in the complex plane """ if n == 1: return db.gps_sato_tate.lookup('1.2.3.1.1a').get('trace_histogram') if n <= 120: plot = sum([line2d([(-2*cos(2*pi*m/n),-2*sin(2*pi*m/n)),(2*cos(2*pi*m/n),2*sin(2*pi*m/n))],thickness=3) for m in range(n)]) else: plot = circle((0,0),2,fill=True) plot.xmin(-2); plot.xmax(2); plot.ymin(-2); plot.ymax(2) plot.set_aspect_ratio(4.0/3.0) plot.axes(False) return encode_plot(plot)
def su2_mu_portrait(n): """ returns an encoded line plot of SU(2) x mu(n) in the complex plane """ if n == 1: return db.gps_st.lookup('1.2.A.1.1a').get('trace_histogram') if n <= 120: plot = sum([line2d([(-2*cos(2*pi*m/n),-2*sin(2*pi*m/n)),(2*cos(2*pi*m/n),2*sin(2*pi*m/n))],thickness=3) for m in range(n)]) else: plot = circle((0,0),2,fill=True) plot.xmin(-2); plot.xmax(2); plot.ymin(-2); plot.ymax(2) plot.set_aspect_ratio(4.0/3.0) plot.axes(False) return encode_plot(plot)
def healpix_diagram(a=1, e=0, shade_polar_region=True): r""" Return a Sage Graphics object diagramming the HEALPix projection boundary and polar triangles for the ellipsoid with major radius `a` and eccentricity `e`. Inessential graphics method. Requires Sage graphics methods. """ from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer # Make Sage types compatible with Numpy. RealNumber = float Integer = int R = auth_rad(a, e) g = Graphics() color = 'black' # Boundary color. shade_color = 'blue' # Polar triangles color. dl = array((R*pi/2,0)) lu = [(-R*pi, R*pi/4),(-R*3*pi/4, R*pi/2)] ld = [(-R*3*pi/4, R*pi/2),(-R*pi/2, R*pi/4)] g += line2d([(-R*pi, -R*pi/4),(-R*pi, R*pi/4)], color=color) g += line2d([(R*pi, R*pi/4),(R*pi, -R*pi/4)], linestyle = '--', color=color) for k in range(4): g += line2d([array(p) + k*dl for p in lu], color=color) g += line2d([array(p) + k*dl for p in ld], linestyle = '--', color=color) g += line2d([array(p) + array((k*R*pi/2 - R*pi/4, -R*3*pi/4)) for p in ld], color=color) g += line2d([array(p) + array((k*R*pi/2 + R*pi/4, -R*3*pi/4)) for p in lu], linestyle = '--', color=color) pn = array((-R*3*pi/4, R*pi/2)) ps = array((-R*3*pi/4, -R*pi/2)) g += point([pn + k*dl for k in range(4)] + [ps + k*dl for k in range(4)], size=20, color=color) g += point([pn + k*dl for k in range(1, 4)] + [ps + k*dl for k in range(1, 4)], color='white', size=10, zorder=3) npp = [(-R*pi, R*pi/4), (-R*3*pi/4, R*pi/2), (-R*pi/2, R*pi/4)] spp = [(-R*pi, -R*pi/4), (-R*3*pi/4, -R*pi/2), (-R*pi/2, -R*pi/4)] if shade_polar_region: for k in range(4): g += polygon([array(p) + k*dl for p in npp], alpha=0.1, color=shade_color) g += text(str(k), array((-R*3*pi/4, R*5*pi/16)) + k*dl, color='red', fontsize=20) g += polygon([array(p) + k*dl for p in spp], alpha=0.1, color=shade_color) g += text(str(k), array((-R*3*pi/4, -R*5*pi/16)) + k*dl, color='red', fontsize=20) return g
def rhealpix_diagram(a=1, e=0, north_square=0, south_square=0, shade_polar_region=True): r""" Return a Sage Graphics object diagramming the rHEALPix projection boundary and polar triangles for the ellipsoid with major radius `a` and eccentricity `e`. Inessential graphics method. Requires Sage graphics methods. """ from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer # Make Sage types compatible with Numpy. RealNumber = float Integer = int R = auth_rad(a, e) g = Graphics() color = 'black' # Boundary color. shade_color = 'blue' # Polar triangles color. north = north_square south = south_square south_sq = [(-R * pi + R * south * pi / 2, -R * pi / 4), (-R * pi + R * south * pi / 2, -R * 3 * pi / 4), (-R * pi + R * (south + 1) * pi / 2, -R * 3 * pi / 4), (-R * pi + R * (south + 1) * pi / 2, -R * pi / 4)] north_sq = [(-R * pi + R * north * pi / 2, R * pi / 4), (-R * pi + R * north * pi / 2, R * 3 * pi / 4), (-R * pi + R * (north + 1) * pi / 2, R * 3 * pi / 4), (-R * pi + R * (north + 1) * pi / 2, R * pi / 4)] # Outline. g += line2d(south_sq, linestyle='--', color=color) g += line2d(north_sq, linestyle='--', color=color) g += line2d([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)], linestyle='--', color=color) g += line2d([ north_sq[0], (-R * pi, R * pi / 4), (-R * pi, -R * pi / 4), south_sq[0] ], color=color) g += line2d([south_sq[3], (R * pi, -R * pi / 4)], color=color) g += line2d([north_sq[3], (R * pi, R * pi / 4)], color=color) g += point([south_sq[0], south_sq[3]], size=20, zorder=3, color=color) g += point([north_sq[0], north_sq[3]], size=20, zorder=3, color=color) g += point([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)], size=20, zorder=3, color=color) g += point([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)], size=10, color='white', zorder=3) if shade_polar_region: # Shade. g += polygon(south_sq, alpha=0.1, color=shade_color) g += polygon(north_sq, alpha=0.1, color=shade_color) # Slice square into polar triangles. g += line2d([south_sq[0], south_sq[2]], color='lightgray') g += line2d([south_sq[1], south_sq[3]], color='lightgray') g += line2d([north_sq[0], north_sq[2]], color='lightgray') g += line2d([north_sq[1], north_sq[3]], color='lightgray') # Label polar triangles. sp = south_sq[0] + R * array((pi / 4, -pi / 4)) np = north_sq[0] + R * array((pi / 4, pi / 4)) shift = R * 3 * pi / 16 g += text(str(south), sp + array((0, shift)), color='red', fontsize=20) g += text(str((south + 1) % 4), sp + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((south + 2) % 4), sp + array((0, -shift)), color='red', rotation=180, fontsize=20) g += text(str((south + 3) % 4), sp + array((-shift, 0)), color='red', rotation=270, fontsize=20) g += text(str(north), np + array((0, -shift)), color='red', fontsize=20) g += text(str((north + 1) % 4), np + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((north + 2) % 4), np + array((0, shift)), color='red', rotation=180, fontsize=20) g += text(str((north + 3) % 4), np + array((-shift, 0)), color='red', rotation=270, fontsize=20) return g
def rhealpix_diagram(a=1, e=0, north_square=0, south_square=0, shade_polar_region=True): r""" Return a Sage Graphics object diagramming the rHEALPix projection boundary and polar triangles for the ellipsoid with major radius `a` and eccentricity `e`. Inessential graphics method. Requires Sage graphics methods. """ from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer # Make Sage types compatible with Numpy. RealNumber = float Integer = int R = auth_rad(a, e) g = Graphics() color = 'black' # Boundary color. shade_color = 'blue' # Polar triangles color. north = north_square south = south_square south_sq = [(-R*pi + R*south*pi/2, -R*pi/4), (-R*pi + R*south*pi/2, -R*3*pi/4), (-R*pi + R*(south + 1)*pi/2, -R*3*pi/4), (-R*pi + R*(south + 1)*pi/2, -R*pi/4)] north_sq = [(-R*pi + R*north*pi/2, R*pi/4), (-R*pi + R*north*pi/2, R*3*pi/4), (-R*pi + R*(north + 1)*pi/2, R*3*pi/4), (-R*pi + R*(north + 1)*pi/2, R*pi/4)] # Outline. g += line2d(south_sq, linestyle = '--', color=color) g += line2d(north_sq, linestyle = '--', color=color) g += line2d([(R*pi, -R*pi/4), (R*pi, R*pi/4)], linestyle='--', color=color) g += line2d([north_sq[0], (-R*pi, R*pi/4), (-R*pi, -R*pi/4), south_sq[0]], color=color) g += line2d([south_sq[3], (R*pi, -R*pi/4)], color=color) g += line2d([north_sq[3],(R*pi, R*pi/4)], color=color) g += point([south_sq[0], south_sq[3]], size=20, zorder=3, color=color) g += point([north_sq[0], north_sq[3]], size=20, zorder=3, color=color) g += point([(R*pi, -R*pi/4), (R*pi, R*pi/4)], size=20, zorder=3, color=color) g += point([(R*pi, -R*pi/4), (R*pi, R*pi/4)], size=10, color='white', zorder=3) if shade_polar_region: # Shade. g += polygon(south_sq, alpha=0.1, color=shade_color) g += polygon(north_sq, alpha=0.1, color=shade_color) # Slice square into polar triangles. g += line2d([south_sq[0], south_sq[2]], color='lightgray') g += line2d([south_sq[1], south_sq[3]], color='lightgray') g += line2d([north_sq[0], north_sq[2]], color='lightgray') g += line2d([north_sq[1], north_sq[3]], color='lightgray') # Label polar triangles. sp = south_sq[0] + R*array((pi/4, -pi/4)) np = north_sq[0] + R*array((pi/4, pi/4)) shift = R*3*pi/16 g += text(str(south), sp + array((0, shift)), color='red', fontsize=20) g += text(str((south + 1) % 4), sp + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((south + 2) % 4), sp + array((0, -shift)), color='red', rotation=180, fontsize=20) g += text(str((south + 3) % 4), sp + array((-shift, 0)), color='red', rotation=270, fontsize=20) g += text(str(north), np + array((0, -shift)), color='red', fontsize=20) g += text(str((north + 1) % 4), np + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((north + 2) % 4), np + array((0, shift)), color='red', rotation=180, fontsize=20) g += text(str((north + 3) % 4), np + array((-shift, 0)), color='red', rotation=270, fontsize=20) return g
def plot(self, textvertices=False, only_simple=False, fontsize=18, sort=False, fact = 0.5, thickness=4, edges_thickness=4, arrowshorten=8, linestyle_simple='solid', linestyle_nonsimple='dashed', arrowsize=2, arrows=False, **options): r""" Plots a SimpleModulesGraph. """ vertex_colors = self._vertex_colors simple_color = self._simple_color nonsimple_color = self._nonsimple_color heights = self._heights if only_simple: for v in vertex_colors[nonsimple_color]: if self.has_vertex(v): self.delete_vertex(v) # while vertex_colors[nonsimple_color].count(v)>0: # vertex_colors[nonsimple_color].remove(v) for j in range(len(heights)): while heights[j].count(v) > 0: heights[j].remove(v) vertex_colors[nonsimple_color] = dict() pos = dict() labels = list() vertices = list() edges = list() min_d = 0.5 widths = [float(sum([len(str(v)) / float(6) + min_d for v in heights[i]])) for i in range(len(heights))] print widths max_w = max(widths) if len(widths) > 1: min_w = min([w for w in widths if w > 3]) else: min_w = 0 print min_w, max_w, widths max_vert = max([len(_) for _ in heights.values()]) for i in range(len(heights)): if sort: heights[i] = sorted(heights[i]) #print heights[i] real_w = widths[i] prev_w = min_w if i == 0 else widths[i - 1] next_w = min_w if i == len(heights) - 1 else widths[i + 1] cur_w = max(float(next_w) * 0.9, float(prev_w) * 0.9, real_w) d = max(2 * float(cur_w - real_w) / len(heights[i]), min_d) print real_w, cur_w print "d = ", d p = [-(cur_w), float(max_vert) * fact * i] w = 0 for j in range(len(heights[i])): v = heights[i][j] p = [p[0] + w + 0.2, p[1]] w = float(len(str(v))) / float(6) p[0] = p[0] + w + d pos[heights[i][j]] = p c = simple_color if vertex_colors[ simple_color].count(v) > 0 else nonsimple_color if textvertices: ct = colors.black.rgb() else: ct = colors.white.rgb() labels.append( text("$\mathbf{" + str(v)[1:len(str(v))-1] + "}$", (p[0] + 0.2, p[1]), rgbcolor=ct, zorder=8, fontsize=fontsize)) print w if textvertices: P = line2d([[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) P += line2d([[p[0] - w, p[1] + 1.1], [p[0] + w + 0.2, p[1] + 1.1]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) P += line2d([[p[0] + w + 0.2, p[1] + 1.1], [p[0] + w + 0.2, p[1] - 0.9]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) P += line2d([[p[0] + w + 0.2, p[1] - 0.9], [p[0] - w, p[1] - 0.9]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) else: polygon2d([[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1], [ p[0] + w + 0.2, p[1] + 1.1], [p[0] + w + 0.2, p[1] - 0.9]], fill=(not textvertices), rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) vertices.append(P) for e in self.edges(): v = e[0] if not self.has_vertex(e[0]) or not self.has_vertex(e[1]): print "deleting edge ", e self.delete_edge(e[0], e[1]) else: c = simple_color if vertex_colors[ simple_color].count(v) > 0 else nonsimple_color if arrows: edges.append(arrow([pos[e[0]][0], pos[e[0]][ 1] + 1.1], [pos[e[1]][0], pos[e[1]][1] - 0.9], rgbcolor=c, zorder=-1, arrowsize=arrowsize, arrowshorten=arrowshorten, width=edges_thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)) else: edges.append(line2d([[pos[e[0]][0], pos[e[0]][1] + 1.1], [pos[e[1]][0], pos[e[1]][1] - 0.9]], rgbcolor=c, zorder=-1, thickness=edges_thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)) print "calculation ended" gp = self.graphplot(dpi=300, pos=pos, vertex_size=2050, figsize=round( float(max_vert) * 1.5), vertex_colors=vertex_colors) gp._plot_components['vertex_labels'] = labels gp._plot_components['vertices'] = vertices gp._plot_components['edges'] = edges #self._pos = pos return gp.plot(**options)
def plot(self, textvertices=False, only_simple=False, fontsize=18, sort=False, fact=0.5, thickness=4, edges_thickness=4, arrowshorten=8, linestyle_simple='solid', linestyle_nonsimple='dashed', arrowsize=2, arrows=False, **options): r""" Plots a SimpleModulesGraph. """ vertex_colors = self._vertex_colors simple_color = self._simple_color nonsimple_color = self._nonsimple_color heights = self._heights if only_simple: for v in vertex_colors[nonsimple_color]: if self.has_vertex(v): self.delete_vertex(v) # while vertex_colors[nonsimple_color].count(v)>0: # vertex_colors[nonsimple_color].remove(v) for j in range(len(heights)): while heights[j].count(v) > 0: heights[j].remove(v) vertex_colors[nonsimple_color] = dict() pos = dict() labels = list() vertices = list() edges = list() min_d = 0.5 widths = [ float(sum([len(str(v)) / float(6) + min_d for v in heights[i]])) for i in range(len(heights)) ] print widths max_w = max(widths) if len(widths) > 1: min_w = min([w for w in widths if w > 3]) else: min_w = 0 print min_w, max_w, widths max_vert = max([len(_) for _ in heights.values()]) for i in range(len(heights)): if sort: heights[i] = sorted(heights[i]) #print heights[i] real_w = widths[i] prev_w = min_w if i == 0 else widths[i - 1] next_w = min_w if i == len(heights) - 1 else widths[i + 1] cur_w = max(float(next_w) * 0.9, float(prev_w) * 0.9, real_w) d = max(2 * float(cur_w - real_w) / len(heights[i]), min_d) print real_w, cur_w print "d = ", d p = [-(cur_w), float(max_vert) * fact * i] w = 0 for j in range(len(heights[i])): v = heights[i][j] p = [p[0] + w + 0.2, p[1]] w = float(len(str(v))) / float(6) p[0] = p[0] + w + d pos[heights[i][j]] = p c = simple_color if vertex_colors[simple_color].count( v) > 0 else nonsimple_color if textvertices: ct = colors.black.rgb() else: ct = colors.white.rgb() labels.append( text("$\mathbf{" + str(v)[1:len(str(v)) - 1] + "}$", (p[0] + 0.2, p[1]), rgbcolor=ct, zorder=8, fontsize=fontsize)) print w if textvertices: P = line2d( [[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) P += line2d( [[p[0] - w, p[1] + 1.1], [p[0] + w + 0.2, p[1] + 1.1]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) P += line2d([[p[0] + w + 0.2, p[1] + 1.1], [p[0] + w + 0.2, p[1] - 0.9]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) P += line2d( [[p[0] + w + 0.2, p[1] - 0.9], [p[0] - w, p[1] - 0.9]], rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) else: polygon2d([[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1], [p[0] + w + 0.2, p[1] + 1.1], [p[0] + w + 0.2, p[1] - 0.9]], fill=(not textvertices), rgbcolor=c, thickness=thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple) vertices.append(P) for e in self.edges(): v = e[0] if not self.has_vertex(e[0]) or not self.has_vertex(e[1]): print "deleting edge ", e self.delete_edge(e[0], e[1]) else: c = simple_color if vertex_colors[simple_color].count( v) > 0 else nonsimple_color if arrows: edges.append( arrow([pos[e[0]][0], pos[e[0]][1] + 1.1], [pos[e[1]][0], pos[e[1]][1] - 0.9], rgbcolor=c, zorder=-1, arrowsize=arrowsize, arrowshorten=arrowshorten, width=edges_thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)) else: edges.append( line2d([[pos[e[0]][0], pos[e[0]][1] + 1.1], [pos[e[1]][0], pos[e[1]][1] - 0.9]], rgbcolor=c, zorder=-1, thickness=edges_thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)) print "calculation ended" gp = self.graphplot(dpi=300, pos=pos, vertex_size=2050, figsize=round(float(max_vert) * 1.5), vertex_colors=vertex_colors) gp._plot_components['vertex_labels'] = labels gp._plot_components['vertices'] = vertices gp._plot_components['edges'] = edges #self._pos = pos return gp.plot(**options)