Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
Bipartite graphs in Sage
Project: Nauty
Path: 2016-04-07-222022.sagews
Views: 108︠62b441c8-d81f-40b4-a22a-49ca66eee128i︠ %md Generate bipartite connected graphs on 6 vertices
Generate bipartite connected graphs on 6 vertices
bipartite6 = list(graphs.nauty_geng('-bc 6')) len(bipartite6)
17
print ', '.join([g.graph6_string() for g in bipartite6])
E?Bw, E?bo, E?qo, E?ro, E?ow, E?zO, E?zo, E?~o, ECR_, ECr_, ECZ?, ECZ_, EEr_, EEh_, EEj_, EEz_, EFz_
show([g.plot(partition=graph_coloring.vertex_coloring(g)) for g in bipartite6])
[]
show(bipartite6)
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
d3-based renderer not yet implemented
[]
bipartite6[0].plot(partition=graph_coloring.first_coloring(bipartite6[0])
Error in lines 1-1
Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 904, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "<string>", line 1
bipartite6[Integer(0)].plot(partition=graph_coloring.first_coloring(bipartite6[Integer(0)])
^
SyntaxError: unexpected EOF while parsing
g=bipartite6[0]
show(g)
d3-based renderer not yet implemented
g.plot(partition=graph_coloring.vertex_coloring(g))
g.plot??
File: /projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/misc/decorators.py Source: @options() def plot(self, **options): r""" Returns a graphics object representing the (di)graph. INPUT: - ``pos`` - an optional positioning dictionary - ``layout`` - what kind of layout to use, takes precedence over pos - 'circular' -- plots the graph with vertices evenly distributed on a circle - 'spring' - uses the traditional spring layout, using the graph's current positions as initial positions - 'tree' - the (di)graph must be a tree. One can specify the root of the tree using the keyword tree_root, otherwise a root will be selected at random. Then the tree will be plotted in levels, depending on minimum distance for the root. - ``vertex_labels`` - whether to print vertex labels - ``edge_labels`` - whether to print edge labels. By default, False, but if True, the result of str(l) is printed on the edge for each label l. Labels equal to None are not printed (to set edge labels, see set_edge_label). - ``vertex_size`` - size of vertices displayed - ``vertex_shape`` - the shape to draw the vertices, for example ``"o"`` for circle or ``"s"`` for square. Whole list is available at http://matplotlib.org/api/markers_api.html. (Not available for multiedge digraphs.) - ``graph_border`` - whether to include a box around the graph - ``vertex_colors`` - optional dictionary to specify vertex colors: each key is a color recognizable by matplotlib, and each corresponding entry is a list of vertices. If a vertex is not listed, it looks invisible on the resulting plot (it doesn't get drawn). - ``edge_colors`` - a dictionary specifying edge colors: each key is a color recognized by matplotlib, and each entry is a list of edges. - ``partition`` - a partition of the vertex set. if specified, plot will show each cell in a different color. vertex_colors takes precedence. - ``talk`` - if true, prints large vertices with white backgrounds so that labels are legible on slides - ``iterations`` - how many iterations of the spring layout algorithm to go through, if applicable - ``color_by_label`` - a boolean or dictionary or function (default: False) whether to color each edge with a different color according to its label; the colors are chosen along a rainbow, unless they are specified by a function or dictionary mapping labels to colors; this option is incompatible with ``edge_color`` and ``edge_colors``. - ``heights`` - if specified, this is a dictionary from a set of floating point heights to a set of vertices - ``edge_style`` - keyword arguments passed into the edge-drawing routine. This currently only works for directed graphs, since we pass off the undirected graph to networkx - ``tree_root`` - a vertex of the tree to be used as the root for the layout="tree" option. If no root is specified, then one is chosen at random. Ignored unless layout='tree'. - ``tree_orientation`` - "up" or "down" (default is "down"). If "up" (resp., "down"), then the root of the tree will appear on the bottom (resp., top) and the tree will grow upwards (resp. downwards). Ignored unless layout='tree'. - ``save_pos`` - save position computed during plotting .. NOTE:: - This method supports any parameter accepted by :meth:`sage.plot.graphics.Graphics.show`. - See the documentation of the :mod:`sage.graphs.graph_plot` module for information and examples of how to define parameters that will be applied to **all** graph plots. - Default parameters for this method *and a specific graph* can also be set through the :class:`~sage.misc.decorators.options` mechanism. For more information on this different way to set default parameters, see the help of the :class:`options decorator <sage.misc.decorators.options>`. - See also the :mod:`sage.graphs.graph_latex` module for ways to use LaTeX to produce an image of a graph. EXAMPLES:: sage: from sage.graphs.graph_plot import graphplot_options sage: list(sorted(graphplot_options.iteritems())) [...] sage: from math import sin, cos, pi sage: P = graphs.PetersenGraph() sage: d = {'#FF0000':[0,5], '#FF9900':[1,6], '#FFFF00':[2,7], '#00FF00':[3,8], '#0000FF':[4,9]} sage: pos_dict = {} sage: for i in range(5): ... x = float(cos(pi/2 + ((2*pi)/5)*i)) ... y = float(sin(pi/2 + ((2*pi)/5)*i)) ... pos_dict[i] = [x,y] ... sage: for i in range(10)[5:]: ... x = float(0.5*cos(pi/2 + ((2*pi)/5)*i)) ... y = float(0.5*sin(pi/2 + ((2*pi)/5)*i)) ... pos_dict[i] = [x,y] ... sage: pl = P.plot(pos=pos_dict, vertex_colors=d) sage: pl.show() :: sage: C = graphs.CubeGraph(8) sage: P = C.plot(vertex_labels=False, vertex_size=0, graph_border=True) sage: P.show() :: sage: G = graphs.HeawoodGraph() sage: for u,v,l in G.edges(): ... G.set_edge_label(u,v,'(' + str(u) + ',' + str(v) + ')') sage: G.plot(edge_labels=True).show() :: sage: D = DiGraph( { 0: [1, 10, 19], 1: [8, 2], 2: [3, 6], 3: [19, 4], 4: [17, 5], 5: [6, 15], 6: [7], 7: [8, 14], 8: [9], 9: [10, 13], 10: [11], 11: [12, 18], 12: [16, 13], 13: [14], 14: [15], 15: [16], 16: [17], 17: [18], 18: [19], 19: []} , sparse=True) sage: for u,v,l in D.edges(): ... D.set_edge_label(u,v,'(' + str(u) + ',' + str(v) + ')') sage: D.plot(edge_labels=True, layout='circular').show() :: sage: from sage.plot.colors import rainbow sage: C = graphs.CubeGraph(5) sage: R = rainbow(5) sage: edge_colors = {} sage: for i in range(5): ... edge_colors[R[i]] = [] sage: for u,v,l in C.edges(): ... for i in range(5): ... if u[i] != v[i]: ... edge_colors[R[i]].append((u,v,l)) sage: C.plot(vertex_labels=False, vertex_size=0, edge_colors=edge_colors).show() :: sage: D = graphs.DodecahedralGraph() sage: Pi = [[6,5,15,14,7],[16,13,8,2,4],[12,17,9,3,1],[0,19,18,10,11]] sage: D.show(partition=Pi) :: sage: G = graphs.PetersenGraph() sage: G.allow_loops(True) sage: G.add_edge(0,0) sage: G.show() :: sage: D = DiGraph({0:[0,1], 1:[2], 2:[3]}, loops=True) sage: D.show() sage: D.show(edge_colors={(0,1,0):[(0,1,None),(1,2,None)],(0,0,0):[(2,3,None)]}) :: sage: pos = {0:[0.0, 1.5], 1:[-0.8, 0.3], 2:[-0.6, -0.8], 3:[0.6, -0.8], 4:[0.8, 0.3]} sage: g = Graph({0:[1], 1:[2], 2:[3], 3:[4], 4:[0]}) sage: g.plot(pos=pos, layout='spring', iterations=0) Graphics object consisting of 11 graphics primitives :: sage: G = Graph() sage: P = G.plot() sage: P.axes() False sage: G = DiGraph() sage: P = G.plot() sage: P.axes() False :: sage: G = graphs.PetersenGraph() sage: G.get_pos() {0: (6.12..., 1.0...), 1: (-0.95..., 0.30...), 2: (-0.58..., -0.80...), 3: (0.58..., -0.80...), 4: (0.95..., 0.30...), 5: (1.53..., 0.5...), 6: (-0.47..., 0.15...), 7: (-0.29..., -0.40...), 8: (0.29..., -0.40...), 9: (0.47..., 0.15...)} sage: P = G.plot(save_pos=True, layout='spring') The following illustrates the format of a position dictionary. sage: G.get_pos() # currently random across platforms, see #9593 {0: [1.17..., -0.855...], 1: [1.81..., -0.0990...], 2: [1.35..., 0.184...], 3: [1.51..., 0.644...], 4: [2.00..., -0.507...], 5: [0.597..., -0.236...], 6: [2.04..., 0.687...], 7: [1.46..., -0.473...], 8: [0.902..., 0.773...], 9: [2.48..., -0.119...]} :: sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}) Graphics object consisting of 14 graphics primitives :: sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}) Graphics object consisting of 14 graphics primitives sage: t.set_edge_label(0,1,-7) sage: t.set_edge_label(0,5,3) sage: t.set_edge_label(0,5,99) sage: t.set_edge_label(1,2,1000) sage: t.set_edge_label(3,2,'spam') sage: t.set_edge_label(2,6,3/2) sage: t.set_edge_label(0,4,66) sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}, edge_labels=True) Graphics object consisting of 20 graphics primitives :: sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(layout='tree') Graphics object consisting of 14 graphics primitives :: sage: t = DiGraph('JCC???@A??GO??CO??GO??') sage: t.plot(layout='tree', tree_root=0, tree_orientation="up") Graphics object consisting of 22 graphics primitives sage: D = DiGraph({0:[1,2,3], 2:[1,4], 3:[0]}) sage: D.plot() Graphics object consisting of 16 graphics primitives sage: D = DiGraph(multiedges=True,sparse=True) sage: for i in range(5): ... D.add_edge((i,i+1,'a')) ... D.add_edge((i,i-1,'b')) sage: D.plot(edge_labels=True,edge_colors=D._color_by_label()) Graphics object consisting of 34 graphics primitives sage: D.plot(edge_labels=True, color_by_label={'a':'blue', 'b':'red'}, edge_style='dashed') Graphics object consisting of 34 graphics primitives sage: g = Graph({}, loops=True, multiedges=True,sparse=True) sage: g.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'), ... (0,1,'e'),(0,1,'f'),(0,1,'f'),(2,1,'g'),(2,2,'h')]) sage: g.plot(edge_labels=True, color_by_label=True, edge_style='dashed') Graphics object consisting of 22 graphics primitives :: sage: S = SupersingularModule(389) sage: H = S.hecke_matrix(2) sage: D = DiGraph(H,sparse=True) sage: P = D.plot() :: sage: G=Graph({'a':['a','b','b','b','e'],'b':['c','d','e'],'c':['c','d','d','d'],'d':['e']},sparse=True) sage: G.show(pos={'a':[0,1],'b':[1,1],'c':[2,0],'d':[1,0],'e':[0,0]}) TESTS:: sage: G = DiGraph({0:{1:'a', 2:'a'}, 1:{0:'b'}, 2:{0:'c'}}) sage: p = G.plot(edge_labels=True, color_by_label={'a':'yellow', 'b':'purple'}); p Graphics object consisting of 14 graphics primitives sage: sorted([x.options()['rgbcolor'] for x in p if isinstance(x, sage.plot.arrow.CurveArrow)]) ['black', 'purple', 'yellow', 'yellow'] """ return self.graphplot(**options).plot()