diff --git a/build/pkgs/configure/checksums.ini b/build/pkgs/configure/checksums.ini index ed7d8cea5bd..9d2198adac4 100644 --- a/build/pkgs/configure/checksums.ini +++ b/build/pkgs/configure/checksums.ini @@ -1,4 +1,4 @@ tarball=configure-VERSION.tar.gz -sha1=e55fd192510499ab59847906bf0abc0e1776aecb -md5=7adfc7ea92837b419c9cf91085b4c0c2 -cksum=2479564476 +sha1=1ef3ccb4e221787756f5d865edd4883d6e8a2aab +md5=f7ca42afb156ba5aa99de96f825948b7 +cksum=3849472062 diff --git a/build/pkgs/configure/package-version.txt b/build/pkgs/configure/package-version.txt index 034ace65fdf..9705a7a73db 100644 --- a/build/pkgs/configure/package-version.txt +++ b/build/pkgs/configure/package-version.txt @@ -1 +1 @@ -8455792fc708dc9b848e9d084e96a6a890bca822 +111d02b0cbc6552b1650930728c7084a72f88a73 diff --git a/src/sage/graphs/base/c_graph.pyx b/src/sage/graphs/base/c_graph.pyx index 8a8877e9f07..83a01eb4f9b 100644 --- a/src/sage/graphs/base/c_graph.pyx +++ b/src/sage/graphs/base/c_graph.pyx @@ -4548,7 +4548,7 @@ cdef class CGraphBackend(GenericGraphBackend): At first, the following graph is acyclic:: sage: D = DiGraph({ 0:[1,2,3], 4:[2,5], 1:[8], 2:[7], 3:[7], 5:[6,7], 7:[8], 6:[9], 8:[10], 9:[10] }) - sage: D.plot(layout='circular').show() + sage: D.plot(layout='circular').show() # optional - sage.plot sage: D.is_directed_acyclic() True diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index dc68357dccf..9b843ca965e 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -158,7 +158,7 @@ class BipartiteGraph(Graph): sage: B = BipartiteGraph(P, partition, check=False) sage: B.left {0, 1, 2, 3, 4} - sage: B.show() + sage: B.show() # optional - sage.plot :: @@ -304,14 +304,14 @@ class BipartiteGraph(Graph): sage: B = BipartiteGraph('F?^T_\n', partition=[[0, 1, 2], [3, 4, 5, 6]], check=False) sage: B.left {0, 1, 2} - sage: B.show() + sage: B.show() # optional - sage.plot #. From a NetworkX bipartite graph:: - sage: import networkx # optional - networkx - sage: G = graphs.OctahedralGraph() # optional - networkx - sage: N = networkx.make_clique_bipartite(G.networkx_graph()) # optional - networkx - sage: B = BipartiteGraph(N) # optional - networkx + sage: import networkx # optional - networkx + sage: G = graphs.OctahedralGraph() # optional - networkx + sage: N = networkx.make_clique_bipartite(G.networkx_graph()) # optional - networkx + sage: B = BipartiteGraph(N) # optional - networkx TESTS: @@ -1464,7 +1464,7 @@ def plot(self, *args, **kwds): EXAMPLES:: sage: B = BipartiteGraph(graphs.CycleGraph(20)) - sage: B.plot() + sage: B.plot() # optional - sage.plot Graphics object consisting of 41 graphics primitives """ if "pos" not in kwds: diff --git a/src/sage/graphs/cliquer.pyx b/src/sage/graphs/cliquer.pyx index e53d90d2dbc..9ff02b8572e 100644 --- a/src/sage/graphs/cliquer.pyx +++ b/src/sage/graphs/cliquer.pyx @@ -115,7 +115,7 @@ def all_max_clique(graph): [2, 6], [2, 8], [3, 4], [3, 7], [3, 9], [4, 5], [4, 8], [5, 10], [5, 11], [6, 10], [6, 11], [7, 8], [7, 11], [8, 10], [9, 10], [9, 11]] sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.cliques_maximum() [[0, 1, 2], [0, 1, 3]] sage: C = graphs.PetersenGraph() @@ -302,7 +302,7 @@ def clique_number(graph): sage: C.clique_number() 4 sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.clique_number() 3 diff --git a/src/sage/graphs/comparability.pyx b/src/sage/graphs/comparability.pyx index 3957e425cc9..0585473a75d 100644 --- a/src/sage/graphs/comparability.pyx +++ b/src/sage/graphs/comparability.pyx @@ -642,7 +642,7 @@ def is_permutation(g, algorithm="greedy", certificate=False, check=True, sage: p1 = Permutation([nn+1 for nn in perm[0]]) sage: p2 = Permutation([nn+1 for nn in perm[1]]) sage: p = p2 * p1.inverse() - sage: p.show(representation = "braid") + sage: p.show(representation="braid") # optional - sage.plot TESTS: diff --git a/src/sage/graphs/connectivity.pyx b/src/sage/graphs/connectivity.pyx index a1241800ac9..89efe9806d1 100644 --- a/src/sage/graphs/connectivity.pyx +++ b/src/sage/graphs/connectivity.pyx @@ -215,12 +215,12 @@ def connected_components_subgraphs(G): sage: from sage.graphs.connectivity import connected_components_subgraphs sage: G = Graph({0: [1, 3], 1: [2], 2: [3], 4: [5, 6], 5: [6]}) sage: L = connected_components_subgraphs(G) - sage: graphs_list.show_graphs(L) + sage: graphs_list.show_graphs(L) # optional - sage.plot sage: D = DiGraph({0: [1, 3], 1: [2], 2: [3], 4: [5, 6], 5: [6]}) sage: L = connected_components_subgraphs(D) - sage: graphs_list.show_graphs(L) + sage: graphs_list.show_graphs(L) # optional - sage.plot sage: L = D.connected_components_subgraphs() - sage: graphs_list.show_graphs(L) + sage: graphs_list.show_graphs(L) # optional - sage.plot TESTS: diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index 54aabd7e2e2..203a6a4f299 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -951,7 +951,7 @@ def is_directed_acyclic(self, certificate=False): At first, the following graph is acyclic:: sage: D = DiGraph({0:[1, 2, 3], 4:[2, 5], 1:[8], 2:[7], 3:[7], 5:[6,7], 7:[8], 6:[9], 8:[10], 9:[10]}) - sage: D.plot(layout='circular').show() + sage: D.plot(layout='circular').show() # optional - sage.plot sage: D.is_directed_acyclic() True @@ -3140,7 +3140,7 @@ def topological_sort(self, implementation="default"): sage: D = DiGraph({0: [1, 2, 3], 4: [2, 5], 1: [8], 2: [7], 3: [7], ....: 5: [6, 7], 7: [8], 6: [9], 8: [10], 9: [10]}) - sage: D.plot(layout='circular').show() + sage: D.plot(layout='circular').show() # optional - sage.plot sage: D.topological_sort() [4, 5, 6, 9, 0, 1, 2, 3, 7, 8, 10] @@ -3220,7 +3220,7 @@ def topological_sort_generator(self): EXAMPLES:: sage: D = DiGraph({0: [1, 2], 1: [3], 2: [3, 4]}) - sage: D.plot(layout='circular').show() + sage: D.plot(layout='circular').show() # optional - sage.plot sage: list(D.topological_sort_generator()) [[0, 1, 2, 3, 4], [0, 2, 1, 3, 4], [0, 2, 1, 4, 3], [0, 2, 4, 1, 3], [0, 1, 2, 4, 3]] diff --git a/src/sage/graphs/generators/basic.py b/src/sage/graphs/generators/basic.py index b3bbb906aa2..27578e76e4b 100644 --- a/src/sage/graphs/generators/basic.py +++ b/src/sage/graphs/generators/basic.py @@ -172,7 +172,7 @@ def CircularLadderGraph(n): Construct and show a circular ladder graph with 26 nodes:: sage: g = graphs.CircularLadderGraph(13) - sage: g.show() # long time + sage: g.show() # long time Create several circular ladder graphs in a Sage graphics array:: @@ -181,13 +181,13 @@ def CircularLadderGraph(n): sage: for i in range(9): ....: k = graphs.CircularLadderGraph(i+3) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ G = Graph(2 * n, name="Circular Ladder graph") G._circle_embedding(list(range(n)), radius=1, angle=pi/2) @@ -265,13 +265,13 @@ def CycleGraph(n): sage: for i in range(9): ....: k = graphs.CycleGraph(i+3) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot Compare to plotting with the spring-layout algorithm:: @@ -281,13 +281,13 @@ def CycleGraph(n): ....: spr = networkx.cycle_graph(i+3) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): # optional - networkx + sage: for i in range(3): # optional - networkx sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) # optional - networkx - sage: G.show() # long time # optional - networkx + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot TESTS: @@ -341,13 +341,13 @@ def CompleteGraph(n): sage: for i in range(9): ....: k = graphs.CompleteGraph(i+3) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot We compare to plotting with the spring-layout algorithm:: @@ -358,13 +358,13 @@ def CompleteGraph(n): ....: spr = networkx.complete_graph(i+3) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): # optional - networkx + sage: for i in range(3): # optional - networkx sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) # optional - networkx - sage: G.show() # long time # optional - networkx + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot Compare the constructors (results will vary):: @@ -382,10 +382,10 @@ def CompleteGraph(n): sage: import networkx # optional - networkx sage: n = networkx.complete_graph(23) # optional - networkx - sage: spring23 = Graph(n) + sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.CompleteGraph(23) - sage: spring23.show() # long time # optional - networkx - sage: posdict23.show() # long time + sage: spring23.show() # long time # optional - networkx sage.plot + sage: posdict23.show() # long time # optional - sage.plot """ G = Graph(n, name="Complete graph") if n == 1: @@ -477,19 +477,20 @@ def CompleteBipartiteGraph(p, q, set_position=True): Two ways of constructing the complete bipartite graph, using different layout algorithms:: - sage: import networkx # optional - networkx - sage: n = networkx.complete_bipartite_graph(389, 157); spring_big = Graph(n) # long time # optional - networkx - sage: posdict_big = graphs.CompleteBipartiteGraph(389, 157) # long time + sage: import networkx # optional - networkx + sage: n = networkx.complete_bipartite_graph(389, 157) # long time # optional - networkx + sage: spring_big = Graph(n) # long time # optional - networkx + sage: posdict_big = graphs.CompleteBipartiteGraph(389, 157) # long time Compare the plotting:: - sage: n = networkx.complete_bipartite_graph(11, 17) # optional - networkx - sage: spring_med = Graph(n) # optional - networkx + sage: n = networkx.complete_bipartite_graph(11, 17) # optional - networkx + sage: spring_med = Graph(n) # optional - networkx sage: posdict_med = graphs.CompleteBipartiteGraph(11, 17) Notice here how the spring-layout tends to center the nodes of `n1`:: - sage: spring_med.show() # long time # optional - networkx + sage: spring_med.show() # long time # optional - networkx sage: posdict_med.show() # long time View many complete bipartite graphs with a Sage Graphics Array, with this @@ -500,29 +501,29 @@ def CompleteBipartiteGraph(p, q, set_position=True): sage: for i in range(9): ....: k = graphs.CompleteBipartiteGraph(i+1,4) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot We compare to plotting with the spring-layout algorithm:: sage: g = [] sage: j = [] - sage: for i in range(9): # optional - networkx + sage: for i in range(9): # optional - networkx ....: spr = networkx.complete_bipartite_graph(i+1,4) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): # optional - networkx + sage: for i in range(3): # optional - networkx sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) # optional - networkx - sage: G.show() # long time # optional - networkx + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot :trac:`12155`:: @@ -972,9 +973,9 @@ def GridGraph(dim_list): sage: dim = [randint(1,4) for i in range(4)] sage: g = graphs.GridGraph(dim) - sage: import networkx # optional - networkx - sage: h = Graph(networkx.grid_graph(list(dim))) # optional - networkx - sage: g.is_isomorphic(h) # optional - networkx + sage: import networkx # optional - networkx + sage: h = Graph(networkx.grid_graph(list(dim))) # optional - networkx + sage: g.is_isomorphic(h) # optional - networkx True Trivial cases:: @@ -1114,13 +1115,13 @@ def LadderGraph(n): sage: for i in range(9): ....: k = graphs.LadderGraph(i+2) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ pos_dict = {} for i in range(n): @@ -1262,14 +1263,14 @@ def StarGraph(n): EXAMPLES:: - sage: import networkx # optional - networkx + sage: import networkx # optional - networkx Compare the plots:: - sage: n = networkx.star_graph(23) # optional - networkx - sage: spring23 = Graph(n) # optional - networkx + sage: n = networkx.star_graph(23) # optional - networkx + sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.StarGraph(23) - sage: spring23.show() # long time # optional - networkx + sage: spring23.show() # long time # optional - networkx sage: posdict23.show() # long time View many star graphs as a Sage Graphics Array @@ -1283,13 +1284,13 @@ def StarGraph(n): sage: for i in range(9): ....: k = graphs.StarGraph(i+3) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot Compared to plotting with the spring-layout algorithm @@ -1297,17 +1298,17 @@ def StarGraph(n): sage: g = [] sage: j = [] - sage: for i in range(9): + sage: for i in range(9): # optional - networkx ....: spr = networkx.star_graph(i+3) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - networkx sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot """ G = Graph({0: list(range(1, n + 1))}, name="Star graph", format="dict_of_lists") G.set_pos({0: (0, 0)}) diff --git a/src/sage/graphs/generators/families.py b/src/sage/graphs/generators/families.py index ccd8af1ff25..f6c7b89bca7 100644 --- a/src/sage/graphs/generators/families.py +++ b/src/sage/graphs/generators/families.py @@ -613,7 +613,7 @@ def BarbellGraph(n1, n2): sage: g = graphs.BarbellGraph(9, 4); g Barbell graph: Graph on 22 vertices - sage: g.show() # long time + sage: g.show() # long time An ``n1 >= 2``, ``n2 >= 0`` barbell graph has order ``2*n1 + n2``. It has the complete graph on ``n1`` vertices as a subgraph. It also has @@ -709,7 +709,7 @@ def LollipopGraph(n1, n2): sage: g = graphs.LollipopGraph(13,4); g Lollipop graph: Graph on 17 vertices - sage: g.show() # long time + sage: g.show() # long time TESTS:: @@ -782,7 +782,7 @@ def TadpoleGraph(n1, n2): sage: g = graphs.TadpoleGraph(13, 4); g Tadpole graph: Graph on 17 vertices - sage: g.show() # long time + sage: g.show() # long time TESTS:: @@ -874,7 +874,7 @@ def DipoleGraph(n): sage: g = graphs.DipoleGraph(13); g Dipole graph: Multi-graph on 2 vertices - sage: g.show() # long time + sage: g.show() # long time TESTS:: @@ -932,7 +932,7 @@ def BubbleSortGraph(n): sage: g = graphs.BubbleSortGraph(4); g Bubble sort: Graph on 24 vertices - sage: g.plot() # long time + sage: g.plot() # long time Graphics object consisting of 61 graphics primitives The bubble sort graph on `n = 1` symbol is the trivial graph `K_1`:: @@ -1080,8 +1080,8 @@ def CirculantGraph(n, adjacency): sage: n = networkx.cycle_graph(23) # optional - networkx sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.CirculantGraph(23,2) - sage: spring23.show() # long time # optional - networkx - sage: posdict23.show() # long time + sage: spring23.show() # long time # optional - networkx + sage: posdict23.show() # long time We next view many cycle graphs as a Sage graphics array. First we use the ``CirculantGraph`` constructor, which fills in @@ -1092,29 +1092,29 @@ def CirculantGraph(n, adjacency): sage: for i in range(9): ....: k = graphs.CirculantGraph(i+4, i+1) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot Compare to plotting with the spring-layout algorithm:: sage: g = [] sage: j = [] - sage: for i in range(9): + sage: for i in range(9): # optional - networkx ....: spr = networkx.cycle_graph(i+3) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - networkx sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot Passing a 1 into adjacency should give the cycle. @@ -1193,21 +1193,21 @@ def CubeGraph(n, embedding=1): ....: k = graphs.CubeGraph(i+1) ....: g.append(k) ... - sage: for i in range(2): + sage: for i in range(2): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) ... - sage: G = graphics_array(j) - sage: G.show(figsize=[6,4]) # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show(figsize=[6,4]) # long time # optional - sage.plot Use the plot options to display larger `n`-cubes:: sage: g = graphs.CubeGraph(9, embedding=1) - sage: g.show(figsize=[12,12],vertex_labels=False, vertex_size=20) # long time + sage: g.show(figsize=[12,12],vertex_labels=False, vertex_size=20) # long time # optional - sage.plot sage: g = graphs.CubeGraph(9, embedding=2) - sage: g.show(figsize=[12,12],vertex_labels=False, vertex_size=20) # long time + sage: g.show(figsize=[12,12],vertex_labels=False, vertex_size=20) # long time # optional - sage.plot AUTHORS: @@ -1442,20 +1442,20 @@ def FriendshipGraph(n): sage: for i in range(9): ....: g = graphs.FriendshipGraph(i + 1) ....: A.append(g) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for j in range(3): ....: n.append(A[3*i + j].plot(vertex_size=20, vertex_labels=False)) ....: B.append(n) - sage: G = graphics_array(B) - sage: G.show() # long time + sage: G = graphics_array(B) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot For `n = 1`, the friendship graph `F_1` is isomorphic to the cycle graph `C_3`, whose visual representation is a triangle. :: sage: G = graphs.FriendshipGraph(1); G Friendship graph: Graph on 3 vertices - sage: G.show() # long time + sage: G.show() # long time # optional - sage.plot sage: G.is_isomorphic(graphs.CycleGraph(3)) True @@ -2392,7 +2392,7 @@ def NKStarGraph(n, k): EXAMPLES:: sage: g = graphs.NKStarGraph(4,2) - sage: g.plot() # long time + sage: g.plot() # long time Graphics object consisting of 31 graphics primitives REFERENCES: @@ -2451,7 +2451,7 @@ def NStarGraph(n): EXAMPLES:: sage: g = graphs.NStarGraph(4) - sage: g.plot() # long time + sage: g.plot() # long time Graphics object consisting of 61 graphics primitives REFERENCES: @@ -2812,7 +2812,7 @@ def HanoiTowerGraph(pegs, disks, labels=True, positions=True): :: sage: H = graphs.HanoiTowerGraph(3, 4, labels=False, positions=False) - sage: H.automorphism_group().is_isomorphic(SymmetricGroup(3)) # optional - sage.groups + sage: H.automorphism_group().is_isomorphic(SymmetricGroup(3)) # optional - sage.groups True sage: H.chromatic_number() 3 @@ -3297,14 +3297,14 @@ def GeneralizedSierpinskiGraph(G, k, stretch=None): sage: G = graphs.HouseGraph() sage: G.get_pos() is not None True - sage: H = graphs.GeneralizedSierpinskiGraph(G, 2) - sage: H.get_pos() is not None + sage: H = graphs.GeneralizedSierpinskiGraph(G, 2) # optional - sage.symbolic + sage: H.get_pos() is not None # optional - sage.symbolic True sage: G = Graph([(0, 1)]) sage: G.get_pos() is not None False - sage: H = graphs.GeneralizedSierpinskiGraph(G, 2) - sage: H.get_pos() is not None + sage: H = graphs.GeneralizedSierpinskiGraph(G, 2) # optional - sage.symbolic + sage: H.get_pos() is not None # optional - sage.symbolic False .. PLOT:: @@ -3398,14 +3398,14 @@ def WheelGraph(n): ....: k = graphs.WheelGraph(i+3) ....: g.append(k) ... - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) ... - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot Next, using the spring-layout algorithm:: @@ -3417,22 +3417,22 @@ def WheelGraph(n): ....: k = Graph(spr) ....: g.append(k) ... - sage: for i in range(3): # optional - networkx + sage: for i in range(3): # optional - networkx sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) ... - sage: G = graphics_array(j) # optional - networkx - sage: G.show() # long time # optional - networkx + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot Compare the plotting:: sage: n = networkx.wheel_graph(23) # optional - networkx sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.WheelGraph(23) - sage: spring23.show() # long time # optional - networkx - sage: posdict23.show() # long time + sage: spring23.show() # long time # optional - networkx + sage: posdict23.show() # long time """ from sage.graphs.generators.basic import CycleGraph if n < 4: @@ -3736,8 +3736,8 @@ def RingedTree(k, vertex_labels=True): EXAMPLES:: sage: G = graphs.RingedTree(5) - sage: P = G.plot(vertex_labels=False, vertex_size=10) - sage: P.show() # long time + sage: P = G.plot(vertex_labels=False, vertex_size=10) # optional - sage.plot + sage: P.show() # long time # optional - sage.plot sage: G.vertices(sort=True) ['', '0', '00', '000', '0000', '0001', '001', '0010', '0011', '01', '010', '0100', '0101', '011', '0110', '0111', '1', '10', '100', @@ -3814,13 +3814,13 @@ def MathonPseudocyclicMergingGraph(M, t): sage: from sage.graphs.generators.families import MathonPseudocyclicMergingGraph as mer sage: from sage.graphs.generators.smallgraphs import _EllipticLinesProjectivePlaneScheme as ES - sage: G = mer(ES(3), 0) # long time + sage: G = mer(ES(3), 0) # long time sage: G.is_strongly_regular(parameters=True) # long time (784, 243, 82, 72) - sage: G = mer(ES(3), 1) # long time + sage: G = mer(ES(3), 1) # long time sage: G.is_strongly_regular(parameters=True) # long time (784, 270, 98, 90) - sage: G = mer(ES(3), 2) # long time + sage: G = mer(ES(3), 2) # long time sage: G.is_strongly_regular(parameters=True) # long time (784, 297, 116, 110) sage: G = mer(ES(2), 2) @@ -3914,12 +3914,12 @@ def MathonPseudocyclicStronglyRegularGraph(t, G=None, L=None): sage: G3x3=graphs.MathonPseudocyclicStronglyRegularGraph(2,G=G,L=L) sage: G3x3.is_strongly_regular(parameters=True) (441, 220, 109, 110) - sage: G3x3.automorphism_group(algorithm="bliss").order() # optional - bliss + sage: G3x3.automorphism_group(algorithm="bliss").order() # optional - bliss 27 sage: G9=graphs.MathonPseudocyclicStronglyRegularGraph(2) sage: G9.is_strongly_regular(parameters=True) (441, 220, 109, 110) - sage: G9.automorphism_group(algorithm="bliss").order() # optional - bliss + sage: G9.automorphism_group(algorithm="bliss").order() # optional - bliss 9 TESTS:: diff --git a/src/sage/graphs/generators/platonic_solids.py b/src/sage/graphs/generators/platonic_solids.py index 536a5f155e6..f36fa8ecf66 100644 --- a/src/sage/graphs/generators/platonic_solids.py +++ b/src/sage/graphs/generators/platonic_solids.py @@ -54,13 +54,13 @@ def TetrahedralGraph(): sage: complete = graphs.CompleteGraph(4) sage: g = [tetra_pos, tetra_spring, wheel, complete] # optional - networkx sage: j = [] - sage: for i in range(2): # optional - networkx + sage: for i in range(2): # optional - networkx sage.plot ....: n = [] ....: for m in range(2): ....: n.append(g[i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) # optional - networkx - sage: G.show() # long time # optional - networkx + sage: G = graphics_array(j) # optional - networkx sage.plot + sage: G.show() # long time # optional - networkx sage.plot """ edges = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] pos = {0: (0, 0), @@ -98,13 +98,13 @@ def HexahedralGraph(): sage: for i in range(9): ....: k = graphs.HexahedralGraph() ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ adj = {0: [1, 3, 4], 1: [2, 5], 2: [3, 6], 3: [7], 4: [5, 7], 5: [6], 6: [7]} pos = { @@ -150,13 +150,13 @@ def OctahedralGraph(): sage: for i in range(9): ....: k = graphs.OctahedralGraph() ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ adj = {0: [1, 2, 3, 4], 1: [2, 3, 5], 2: [4, 5], 3: [4, 5], 4: [5]} G = Graph(adj, format='dict_of_lists', name="Octahedron") @@ -194,13 +194,13 @@ def IcosahedralGraph(): sage: for i in range(9): ....: k = graphs.IcosahedralGraph() ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ adj = {0: [1, 5, 7, 8, 11], 1: [2, 5, 6, 8], 2: [3, 6, 8, 9], 3: [4, 6, 9, 10], 4: [5, 6, 10, 11], 5: [6, 11], @@ -238,13 +238,13 @@ def DodecahedralGraph(): sage: for i in range(9): ....: k = graphs.DodecahedralGraph() ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ adj = {0: [1, 10, 19], 1: [2, 8], 2: [3, 6], 3: [4, 19], 4: [5, 17], 5: [6, 15], 6: [7], 7: [8, 14], 8: [9], 9: [10, 13], 10: [11], diff --git a/src/sage/graphs/generators/random.py b/src/sage/graphs/generators/random.py index c2d43aae2d7..a947f4488c9 100644 --- a/src/sage/graphs/generators/random.py +++ b/src/sage/graphs/generators/random.py @@ -78,13 +78,13 @@ def RandomGNP(n, p, seed=None, fast=True, algorithm='Sage'): sage: for i in range(9): ....: k = graphs.RandomGNP(i+3,.43) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot sage: graphs.RandomGNP(4,1) Complete graph: Graph on 4 vertices @@ -167,13 +167,13 @@ def RandomBarabasiAlbert(n, m, seed=None): sage: for i in range(1,10): ....: k = graphs.RandomBarabasiAlbert(i+3, 3) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot When `m = 1`, the generated graph is a tree:: @@ -694,13 +694,13 @@ def RandomGNM(n, m, dense=False, seed=None): sage: for i in range(9): ....: k = graphs.RandomGNM(i+3, i^2-i) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - sage.plot ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - sage.plot + sage: G.show() # long time # optional - sage.plot """ if seed is None: seed = int(current_randstate().long_seed() % sys.maxsize) @@ -1889,7 +1889,7 @@ def RandomTriangulation(n, set_position=False, k=3, seed=None): True sage: G.girth() 3 - sage: G.plot(vertex_size=0, vertex_labels=False) + sage: G.plot(vertex_size=0, vertex_labels=False) # optional - sage.plot Graphics object consisting of 13 graphics primitives sage: H = graphs.RandomTriangulation(7, k=5) @@ -2106,9 +2106,9 @@ def RandomBicubicPlanar(n, seed=None): True sage: G.is_bipartite() and G.is_planar() and G.is_regular(3) True - sage: dic = {'red':[v for v in G.vertices(sort=False) if v[0] == 'n'], + sage: dic = {'red': [v for v in G.vertices(sort=False) if v[0] == 'n'], ....: 'blue': [v for v in G.vertices(sort=False) if v[0] != 'n']} - sage: G.plot(vertex_labels=False,vertex_size=20,vertex_colors=dic) + sage: G.plot(vertex_labels=False, vertex_size=20, vertex_colors=dic) # optional - sage.plot Graphics object consisting of ... graphics primitives .. PLOT:: diff --git a/src/sage/graphs/generators/smallgraphs.py b/src/sage/graphs/generators/smallgraphs.py index 8a4a72b13f7..f25d5b4e561 100644 --- a/src/sage/graphs/generators/smallgraphs.py +++ b/src/sage/graphs/generators/smallgraphs.py @@ -1577,7 +1577,7 @@ def DoubleStarSnark(): False sage: g.automorphism_group().cardinality() 80 - sage: g.show() + sage: g.show() # optional - sage.plot """ d = {0: [1, 14, 15], 1: [0, 2, 11], @@ -1836,7 +1836,7 @@ def ClebschGraph(): 4 sage: g.diameter() 2 - sage: g.show(figsize=[10, 10]) # long time + sage: g.show(figsize=[10, 10]) # long time """ g = Graph(pos={}) x = 0 @@ -1904,11 +1904,11 @@ def DejterGraph(): EXAMPLES:: - sage: g = graphs.DejterGraph(); g + sage: g = graphs.DejterGraph(); g # optional - sage.rings.finite_rings Dejter Graph: Graph on 112 vertices - sage: g.is_regular(k=6) + sage: g.is_regular(k=6) # optional - sage.rings.finite_rings True - sage: g.girth() + sage: g.girth() # optional - sage.rings.finite_rings 4 """ from sage.graphs.generators.families import CubeGraph @@ -2668,11 +2668,12 @@ def GolombGraph(): and 18 edges. It has chromatic number 4, diameter 3, radius 2 and girth 3. It can be drawn in the plane as a unit distance graph:: - sage: G = graphs.GolombGraph(); G + sage: G = graphs.GolombGraph(); G # optional - sage.symbolic Golomb graph: Graph on 10 vertices - sage: pos = G.get_pos() - sage: dist2 = lambda u,v:(u[0]-v[0])**2 + (u[1]-v[1])**2 - sage: all(dist2(pos[u], pos[v]) == 1 for u, v in G.edge_iterator(labels=None)) + sage: pos = G.get_pos() # optional - sage.symbolic + sage: def dist2(u, v): + ....: return (u[0]-v[0])**2 + (u[1]-v[1])**2 + sage: all(dist2(pos[u], pos[v]) == 1 for u, v in G.edge_iterator(labels=None)) # optional - sage.symbolic True """ edge_dict = { @@ -3610,8 +3611,8 @@ def McGeeGraph(embedding=2): 7 sage: g.diameter() 4 - sage: g.show() - sage: graphs.McGeeGraph(embedding=1).show() # long time + sage: g.show() # optional - sage.plot + sage: graphs.McGeeGraph(embedding=1).show() # long time # optional - sage.plot TESTS:: @@ -3725,7 +3726,7 @@ def MoebiusKantorGraph(): Moebius-Kantor Graph: Graph on 16 vertices sage: MK.graph6_string() 'OhCGKE?O@?ACAC@I?Q_AS' - sage: (graphs.MoebiusKantorGraph()).show() # long time + sage: (graphs.MoebiusKantorGraph()).show() # long time # optional - sage.plot """ from sage.graphs.generators.families import GeneralizedPetersenGraph G = GeneralizedPetersenGraph(8, 3) @@ -3743,38 +3744,38 @@ def MoserSpindle(): The Moser spindle is a planar graph having 7 vertices and 11 edges:: - sage: G = graphs.MoserSpindle(); G + sage: G = graphs.MoserSpindle(); G # optional - sage.symbolic Moser spindle: Graph on 7 vertices - sage: G.is_planar() + sage: G.is_planar() # optional - sage.symbolic True - sage: G.order() + sage: G.order() # optional - sage.symbolic 7 - sage: G.size() + sage: G.size() # optional - sage.symbolic 11 It is a Hamiltonian graph with radius 2, diameter 2, and girth 3:: - sage: G.is_hamiltonian() + sage: G.is_hamiltonian() # optional - sage.symbolic True - sage: G.radius() + sage: G.radius() # optional - sage.symbolic 2 - sage: G.diameter() + sage: G.diameter() # optional - sage.symbolic 2 - sage: G.girth() + sage: G.girth() # optional - sage.symbolic 3 The Moser spindle can be drawn in the plane as a unit distance graph, has chromatic number 4, and its automorphism group is isomorphic to the dihedral group `D_4`:: - sage: pos = G.get_pos() - sage: all(sum((ui-vi)**2 for ui, vi in zip(pos[u], pos[v])) == 1 + sage: pos = G.get_pos() # optional - sage.symbolic + sage: all(sum((ui-vi)**2 for ui, vi in zip(pos[u], pos[v])) == 1 # optional - sage.symbolic ....: for u, v in G.edge_iterator(labels=None)) True - sage: G.chromatic_number() + sage: G.chromatic_number() # optional - sage.symbolic 4 - sage: ag = G.automorphism_group() - sage: ag.is_isomorphic(DihedralGroup(4)) + sage: ag = G.automorphism_group() # optional - sage.symbolic + sage: ag.is_isomorphic(DihedralGroup(4)) # optional - sage.symbolic True """ edge_dict = { @@ -3820,8 +3821,8 @@ def NauruGraph(embedding=2): 6 sage: g.diameter() 4 - sage: g.show() - sage: graphs.NauruGraph(embedding=1).show() # long time + sage: g.show() # optional - sage.plot + sage: graphs.NauruGraph(embedding=1).show() # long time # optional - sage.plot TESTS:: @@ -3856,9 +3857,9 @@ def PappusGraph(): EXAMPLES:: sage: G = graphs.PappusGraph() - sage: G.show() # long time + sage: G.show() # long time # optional - sage.plot sage: L = graphs.LCFGraph(18, [5,7,-7,7,-7,-5], 3) - sage: L.show() # long time + sage: L.show() # long time # optional - sage.plot sage: G.is_isomorphic(L) True """ @@ -3922,9 +3923,9 @@ def PetersenGraph(): ....: 3:[2,4,8], 4:[0,3,9], 5:[0,7,8], ....: 6:[1,8,9], 7:[2,5,9], 8:[3,5,6], ....: 9:[4,6,7]}) - sage: petersen_spring.show() # long time + sage: petersen_spring.show() # long time # optional - sage.plot sage: petersen_database = graphs.PetersenGraph() - sage: petersen_database.show() # long time + sage: petersen_database.show() # long time # optional - sage.plot """ from sage.graphs.generators.families import GeneralizedPetersenGraph P = GeneralizedPetersenGraph(5, 2) @@ -4017,7 +4018,7 @@ def SchlaefliGraph(): Checking that the method actually returns the Schläfli graph:: sage: S = graphs.SchlaefliGraph() - sage: S.is_strongly_regular(parameters = True) + sage: S.is_strongly_regular(parameters=True) (27, 16, 10, 8) The graph is vertex-transitive:: @@ -4315,7 +4316,7 @@ def ThomsenGraph(): Thomsen graph: Graph on 6 vertices sage: T.graph6_string() 'EFz_' - sage: (graphs.ThomsenGraph()).show() # long time + sage: (graphs.ThomsenGraph()).show() # long time # optional - sage.plot """ from sage.graphs.generators.basic import CompleteBipartiteGraph G = CompleteBipartiteGraph(3, 3) @@ -4423,7 +4424,7 @@ def Tutte12Cage(): 12 sage: g.diameter() 6 - sage: g.show() + sage: g.show() # optional - sage.plot """ L = [17, 27, -13, -59, -35, 35, -11, 13, -53, 53, -27, 21, 57, 11, -21, -57, 59, -17] @@ -4456,7 +4457,7 @@ def TutteCoxeterGraph(embedding=2): 8 sage: g.diameter() 4 - sage: g.show() + sage: g.show() # optional - sage.plot sage: graphs.TutteCoxeterGraph(embedding=1).show() # long time TESTS:: @@ -4569,7 +4570,7 @@ def WagnerGraph(): 4 sage: g.diameter() 2 - sage: g.show() + sage: g.show() # optional - sage.plot """ from sage.graphs.generators.families import LCFGraph g = LCFGraph(8, [4], 8) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index e4e6beea1b7..2dfe096c547 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -3687,8 +3687,8 @@ def get_pos(self, dim=2): sage: G.get_pos() sage: G.get_pos() is None True - sage: P = G.plot(save_pos=True) - sage: G.get_pos() + sage: P = G.plot(save_pos=True) # optional - sage.plot + sage: G.get_pos() # optional - sage.plot {} Some of the named graphs come with a pre-specified positioning:: @@ -3813,8 +3813,8 @@ def set_pos(self, pos, dim=2): invalid positioning are ignored:: sage: G.set_pos(dict(enumerate('abcdefghi'))) - sage: P = G.plot() # positions are ignored - sage: G.get_pos() is None + sage: P = G.plot() # positions are ignored # optional - sage.plot + sage: G.get_pos() is None # optional - sage.plot True """ if pos is None: @@ -5508,7 +5508,7 @@ def is_circular_planar(self, on_embedding=None, kuratowski=False, EXAMPLES:: sage: g439 = Graph({1: [5, 7], 2: [5, 6], 3: [6, 7], 4: [5, 6, 7]}) - sage: g439.show() + sage: g439.show() # optional - sage.plot sage: g439.is_circular_planar(boundary=[1, 2, 3, 4]) False sage: g439.is_circular_planar(kuratowski=True, boundary=[1, 2, 3, 4]) @@ -10624,7 +10624,8 @@ def delete_vertex(self, vertex, in_order=False): EXAMPLES:: sage: G = Graph(graphs.WheelGraph(9)) - sage: G.delete_vertex(0); G.show() + sage: G.delete_vertex(0) + sage: G.show() # optional - sage.plot :: @@ -15928,9 +15929,9 @@ def centrality_betweenness(self, k=None, normalized=True, weight=None, 9: 3.333333333333333, 10: 3.333333333333333, 11: 3.333333333333333} sage: D = DiGraph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: D.show(figsize=[2,2]) + sage: D.show(figsize=[2,2]) # optional - sage.plot sage: D = D.to_undirected() - sage: D.show(figsize=[2,2]) + sage: D.show(figsize=[2,2]) # optional - sage.plot sage: D.centrality_betweenness() # abs tol abs 1e-10 {0: 0.16666666666666666, 1: 0.16666666666666666, 2: 0.0, 3: 0.0} @@ -16068,11 +16069,11 @@ def centrality_closeness(self, vert=None, by_weight=False, algorithm=None, 8: 0.61111111111111..., 9: 0.61111111111111..., 10: 0.61111111111111..., 11: 0.61111111111111...} sage: D = DiGraph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: D.show(figsize=[2,2]) + sage: D.show(figsize=[2,2]) # optional - sage.plot sage: D.centrality_closeness(vert=[0,1]) {0: 1.0, 1: 0.3333333333333333} sage: D = D.to_undirected() - sage: D.show(figsize=[2,2]) + sage: D.show(figsize=[2,2]) # optional - sage.plot sage: D.centrality_closeness() {0: 1.0, 1: 1.0, 2: 0.75, 3: 0.75} @@ -18068,8 +18069,9 @@ def breadth_first_search(self, start, ignore_direction=False, [0, 1, 4, 5, 2, 6, 3, 9, 7, 8] sage: D = DiGraph({0: [1, 3], 1: [0, 2], 2: [0, 3], 3: [4]}) - sage: D.show() - sage: list(D.breadth_first_search(4, neighbors=D.neighbor_in_iterator, report_distance=True)) + sage: D.show() # optional - sage.plot + sage: list(D.breadth_first_search(4, neighbors=D.neighbor_in_iterator, + ....: report_distance=True)) [(4, 0), (3, 1), (0, 2), (2, 2), (1, 3)] sage: C = graphs.CycleGraph(4) @@ -18412,11 +18414,11 @@ def add_cycle(self, vertices): sage: G = Graph() sage: G.add_vertices(range(10)); G Graph on 10 vertices - sage: show(G) + sage: show(G) # optional - sage.plot sage: G.add_cycle(list(range(10, 20))) - sage: show(G) + sage: show(G) # optional - sage.plot sage: G.add_cycle(list(range(10))) - sage: show(G) + sage: show(G) # optional - sage.plot :: @@ -18468,11 +18470,11 @@ def add_path(self, vertices): sage: G = Graph() sage: G.add_vertices(range(10)); G Graph on 10 vertices - sage: show(G) + sage: show(G) # optional - sage.plot sage: G.add_path(list(range(10, 20))) - sage: show(G) + sage: show(G) # optional - sage.plot sage: G.add_path(list(range(10))) - sage: show(G) + sage: show(G) # optional - sage.plot :: @@ -18497,10 +18499,10 @@ def complement(self): EXAMPLES:: sage: P = graphs.PetersenGraph() - sage: P.plot() # long time + sage: P.plot() # long time # optional - sage.plot Graphics object consisting of 26 graphics primitives sage: PC = P.complement() - sage: PC.plot() # long time + sage: PC.plot() # long time # optional - sage.plot Graphics object consisting of 41 graphics primitives :: @@ -19668,7 +19670,7 @@ def layout_spring(self, by_component=True, **options): 4: [2.14..., -0.30...], 5: [2.80..., 0.22...]} sage: g = graphs.LadderGraph(7) - sage: g.plot(layout="spring") + sage: g.plot(layout="spring") # optional - sage.plot Graphics object consisting of 34 graphics primitives """ return spring_layout_fast(self, by_component=by_component, **options) @@ -19708,7 +19710,7 @@ def layout_ranked(self, heights=None, dim=2, spring=False, **options): 4: [1.33..., 1], 5: [1.33..., 2]} sage: g = graphs.LadderGraph(7) - sage: g.plot(layout="ranked", heights={i: (i, i+7) for i in range(7)}) + sage: g.plot(layout="ranked", heights={i: (i, i+7) for i in range(7)}) # optional - sage.plot Graphics object consisting of 34 graphics primitives """ assert heights is not None @@ -19836,7 +19838,7 @@ def layout_circular(self, dim=2, center=(0, 0), radius=1, shift=0, angle=0, **op 4: (0.43..., -0.90...), 5: (0.97..., -0.22...), 6: (0.78..., 0.62...)} - sage: G.plot(layout="circular") + sage: G.plot(layout="circular") # optional - sage.plot Graphics object consisting of 22 graphics primitives """ assert dim == 2, "3D circular layout not implemented" @@ -19870,18 +19872,18 @@ def layout_forest(self, tree_orientation="down", forest_roots=None, sage: G = graphs.RandomTree(4) + graphs.RandomTree(5) + graphs.RandomTree(6) sage: p = G.layout_forest() - sage: G.plot(pos=p) # random + sage: G.plot(pos=p) # random # optional - sage.plot Graphics object consisting of 28 graphics primitives sage: H = graphs.PathGraph(5) + graphs.PathGraph(5) + graphs.BalancedTree(2,2) sage: p = H.layout_forest(forest_roots=[14,3]) - sage: H.plot(pos=p) + sage: H.plot(pos=p) # optional - sage.plot Graphics object consisting of 32 graphics primitives TESTS:: sage: G = Graph(0) - sage: G.plot(layout='forest') + sage: G.plot(layout='forest') # optional - sage.plot Graphics object consisting of 0 graphics primitives Works for forests that are trees:: @@ -19942,16 +19944,16 @@ def layout_tree(self, tree_orientation="down", tree_root=None, EXAMPLES:: sage: G = graphs.RandomTree(80) - sage: G.plot(layout="tree", tree_orientation="right") + sage: G.plot(layout="tree", tree_orientation="right") # optional - sage.plot Graphics object consisting of 160 graphics primitives sage: T = graphs.RandomLobster(25, 0.3, 0.3) - sage: T.show(layout='tree', tree_orientation='up') + sage: T.show(layout='tree', tree_orientation='up') # optional - sage.plot sage: G = graphs.HoffmanSingletonGraph() sage: T = Graph() sage: T.add_edges(G.min_spanning_tree(starting_vertex=0)) - sage: T.show(layout='tree', tree_root=0) + sage: T.show(layout='tree', tree_root=0) # optional - sage.plot sage: G = graphs.BalancedTree(2, 2) sage: G.layout_tree(tree_root=0) @@ -19964,7 +19966,7 @@ def layout_tree(self, tree_orientation="down", tree_root=None, 6: [0.0, -2]} sage: G = graphs.BalancedTree(2, 4) - sage: G.plot(layout="tree", tree_root=0, tree_orientation="up") + sage: G.plot(layout="tree", tree_root=0, tree_orientation="up") # optional - sage.plot Graphics object consisting of 62 graphics primitives Using the embedding when it exists:: @@ -19982,7 +19984,7 @@ def layout_tree(self, tree_orientation="down", tree_root=None, 6: [2.0, -1], 7: [1.0, -2], 8: [0.0, -2]} - sage: T.plot(layout="tree", tree_root=3) + sage: T.plot(layout="tree", tree_root=3) # optional - sage.plot Graphics object consisting of 18 graphics primitives TESTS:: @@ -19998,12 +20000,12 @@ def layout_tree(self, tree_orientation="down", tree_root=None, 6: [-2, 0.0]} sage: G = graphs.CycleGraph(3) - sage: G.plot(layout='tree') + sage: G.plot(layout='tree') # optional - sage.plot Traceback (most recent call last): ... RuntimeError: cannot use tree layout on this graph: self.is_tree() returns False sage: G = Graph(0) - sage: G.plot(layout='tree') + sage: G.plot(layout='tree') # optional - sage.plot Graphics object consisting of 0 graphics primitives """ if dim != 2: @@ -20162,16 +20164,16 @@ def layout_graphviz(self, dim=2, prog='dot', **options): By default, an acyclic layout is computed using ``graphviz``'s ``dot`` layout program. One may specify an alternative layout program:: - sage: g.plot(layout = "graphviz", prog = "dot") # optional - dot2tex graphviz + sage: g.plot(layout="graphviz", prog="dot") # optional - dot2tex graphviz Graphics object consisting of 29 graphics primitives - sage: g.plot(layout = "graphviz", prog = "neato") # optional - dot2tex graphviz + sage: g.plot(layout="graphviz", prog="neato") # optional - dot2tex graphviz Graphics object consisting of 29 graphics primitives - sage: g.plot(layout = "graphviz", prog = "twopi") # optional - dot2tex graphviz + sage: g.plot(layout="graphviz", prog="twopi") # optional - dot2tex graphviz Graphics object consisting of 29 graphics primitives - sage: g.plot(layout = "graphviz", prog = "fdp") # optional - dot2tex graphviz + sage: g.plot(layout="graphviz", prog="fdp") # optional - dot2tex graphviz Graphics object consisting of 29 graphics primitives sage: g = graphs.BalancedTree(5,2) - sage: g.plot(layout = "graphviz", prog = "circo") # optional - dot2tex graphviz + sage: g.plot(layout="graphviz", prog="circo") # optional - dot2tex graphviz Graphics object consisting of 62 graphics primitives .. TODO:: @@ -20296,7 +20298,7 @@ def _circle_embedding(self, vertices, center=(0, 0), radius=1, shift=0, angle=0, sage: g = graphs.CycleGraph(5) sage: g._circle_embedding([0, 2, 4, 1, 3], radius=2, shift=.5) - sage: g.show() + sage: g.show() # optional - sage.plot sage: g._circle_embedding(g.vertices(sort=True), angle=0) sage: g._pos[0] @@ -20376,9 +20378,10 @@ def _line_embedding(self, vertices, first=(0, 0), last=(0, 1), return_dict=False sage: g = graphs.PathGraph(5) sage: g._line_embedding([0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1)) - sage: g.show() + sage: g.show() # optional - sage.plot - sage: pos = g._line_embedding([4, 2, 0, 1, 3], first=(-1, -1), last=(1, 1), return_dict=True) + sage: pos = g._line_embedding([4, 2, 0, 1, 3], first=(-1, -1), last=(1, 1), + ....: return_dict=True) sage: pos[0] (0.0, 0.0) sage: g.get_pos()[0] @@ -20445,18 +20448,19 @@ def graphplot(self, **options): 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: GP = g.graphplot(edge_labels=True, color_by_label=True, edge_style='dashed') - sage: GP.plot() + sage: GP = g.graphplot(edge_labels=True, color_by_label=True, # optional - sage.plot + ....: edge_style='dashed') + sage: GP.plot() # optional - sage.plot Graphics object consisting of 22 graphics primitives We can modify the :class:`~sage.graphs.graph_plot.GraphPlot` object. Notice that the changes are cumulative:: - sage: GP.set_edges(edge_style='solid') - sage: GP.plot() + sage: GP.set_edges(edge_style='solid') # optional - sage.plot + sage: GP.plot() # optional - sage.plot Graphics object consisting of 22 graphics primitives - sage: GP.set_vertices(talk=True) - sage: GP.plot() + sage: GP.set_vertices(talk=True) # optional - sage.plot + sage: GP.plot() # optional - sage.plot Graphics object consisting of 22 graphics primitives """ from sage.graphs.graph_plot import GraphPlot @@ -20626,7 +20630,8 @@ def plot(self, **options): 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: 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)) @@ -20636,21 +20641,21 @@ def plot(self, **options): ....: 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: pl = P.plot(pos=pos_dict, vertex_colors=d) # optional - sage.plot + sage: pl.show() # optional - sage.plot :: sage: C = graphs.CubeGraph(8) - sage: P = C.plot(vertex_labels=False, vertex_size=0, graph_border=True) - sage: P.show() + sage: P = C.plot(vertex_labels=False, vertex_size=0, graph_border=True) # optional - sage.plot + sage: P.show() # optional - sage.plot :: sage: G = graphs.HeawoodGraph() sage: for u, v, l in G.edges(sort=False): ....: G.set_edge_label(u, v, '(' + str(u) + ',' + str(v) + ')') - sage: G.plot(edge_labels=True).show() + sage: G.plot(edge_labels=True).show() # optional - sage.plot :: @@ -20661,7 +20666,7 @@ def plot(self, **options): ....: 16: [17], 17: [18], 18: [19]}, sparse=True) sage: for u,v,l in D.edges(sort=False): ....: D.set_edge_label(u, v, '(' + str(u) + ',' + str(v) + ')') - sage: D.plot(edge_labels=True, layout='circular').show() + sage: D.plot(edge_labels=True, layout='circular').show() # optional - sage.plot :: @@ -20673,43 +20678,45 @@ def plot(self, **options): ....: 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: C.plot(vertex_labels=False, vertex_size=0, # optional - sage.plot + ....: 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: D.show(partition=Pi) # optional - sage.plot :: sage: G = graphs.PetersenGraph() sage: G.allow_loops(True) sage: G.add_edge(0, 0) - sage: G.show() + sage: G.show() # optional - sage.plot :: 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: D.show() # optional - sage.plot + sage: D.show(edge_colors={(0, 1, 0): [(0, 1, None), (1, 2, None)], # optional - sage.plot + ....: (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) + sage: g.plot(pos=pos, layout='spring', iterations=0) # optional - sage.plot Graphics object consisting of 11 graphics primitives :: sage: G = Graph() - sage: P = G.plot() - sage: P.axes() + sage: P = G.plot() # optional - sage.plot + sage: P.axes() # optional - sage.plot False sage: G = DiGraph() - sage: P = G.plot() - sage: P.axes() + sage: P = G.plot() # optional - sage.plot + sage: P.axes() # optional - sage.plot False :: @@ -20726,11 +20733,11 @@ def plot(self, **options): 7: (-0.29..., -0.40...), 8: (0.29..., -0.40...), 9: (0.47..., 0.15...)} - sage: P = G.plot(save_pos=True, layout='spring') + sage: P = G.plot(save_pos=True, layout='spring') # optional - sage.plot The following illustrates the format of a position dictionary:: - sage: G.get_pos() # currently random across platforms, see #9593 + sage: G.get_pos() # currently random across platforms, see #9593 # optional - sage.plot {0: [1.17..., -0.855...], 1: [1.81..., -0.0990...], 2: [1.35..., 0.184...], @@ -20746,14 +20753,14 @@ def plot(self, **options): 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]}) + sage: t.plot(heights={0: [0], 1: [4, 5, 1], 2: [2], 3: [3, 6]}) # optional - sage.plot 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]}) + sage: t.plot(heights={0: [0], 1: [4, 5, 1], 2: [2], 3: [3, 6]}) # optional - sage.plot Graphics object consisting of 14 graphics primitives sage: t.set_edge_label(0, 1, -7) sage: t.set_edge_label(0, 5, 3) @@ -20762,58 +20769,63 @@ def plot(self, **options): 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) + sage: t.plot(heights={0: [0], 1: [4, 5, 1], 2: [2], 3: [3, 6]}, # optional - sage.plot + ....: 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') + sage: t.plot(layout='tree') # optional - sage.plot 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") + sage: t.plot(layout='tree', tree_root=0, tree_orientation="up") # optional - sage.plot Graphics object consisting of 22 graphics primitives sage: D = DiGraph({0: [1, 2, 3], 2: [1, 4], 3: [0]}) - sage: D.plot() + sage: D.plot() # optional - sage.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()) + sage: D.plot(edge_labels=True, edge_colors=D._color_by_label()) # optional - sage.plot Graphics object consisting of 34 graphics primitives - sage: D.plot(edge_labels=True, color_by_label={'a': 'blue', 'b': 'red'}, edge_style='dashed') + sage: D.plot(edge_labels=True, color_by_label={'a': 'blue', 'b': 'red'}, # optional - sage.plot + ....: 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') + sage: g.plot(edge_labels=True, color_by_label=True, edge_style='dashed') # optional - sage.plot 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: D = DiGraph(H, sparse=True) + sage: P = D.plot() # optional - sage.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]}) + 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]}) # optional - sage.plot 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 + sage: p = G.plot(edge_labels=True, # optional - sage.plot + ....: 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)]) + sage: sorted(x.options()['rgbcolor'] for x in p # optional - sage.plot + ....: if isinstance(x, sage.plot.arrow.CurveArrow)) ['black', 'purple', 'yellow', 'yellow'] """ return self.graphplot(**options).plot() @@ -20839,8 +20851,8 @@ def show(self, method="matplotlib", **kwds): EXAMPLES:: sage: C = graphs.CubeGraph(8) - sage: P = C.plot(vertex_labels=False, vertex_size=0, graph_border=True) - sage: P.show() # long time (3s on sage.math, 2011) + sage: P = C.plot(vertex_labels=False, vertex_size=0, graph_border=True) # optional - sage.plot + sage: P.show() # long time (3s on sage.math, 2011) # optional - sage.plot """ if method == "js": @@ -20928,7 +20940,7 @@ def plot3d(self, bgcolor=(1, 1, 1), EXAMPLES:: sage: G = graphs.CubeGraph(5) - sage: G.plot3d(iterations=500, edge_size=None, vertex_size=0.04) # long time + sage: G.plot3d(iterations=500, edge_size=None, vertex_size=0.04) # long time, optional - sage.plot Graphics3d Object We plot a fairly complicated Cayley graph:: @@ -20936,29 +20948,37 @@ def plot3d(self, bgcolor=(1, 1, 1), sage: A5 = AlternatingGroup(5); A5 Alternating group of order 5!/2 as a permutation group sage: G = A5.cayley_graph() - sage: G.plot3d(vertex_size=0.03, edge_size=0.01, vertex_colors={(1,1,1): list(G)}, bgcolor=(0,0,0), color_by_label=True, iterations=200) # long time + sage: G.plot3d(vertex_size=0.03, edge_size=0.01, # long time, optional - sage.plot + ....: vertex_colors={(1,1,1): list(G)}, bgcolor=(0,0,0), + ....: color_by_label=True, iterations=200) Graphics3d Object Some :class:`~sage.plot.plot3d.tachyon.Tachyon` examples:: sage: D = graphs.DodecahedralGraph() - sage: P3D = D.plot3d(engine='tachyon') - sage: P3D.show() # long time + sage: P3D = D.plot3d(engine='tachyon') # optional - sage.plot + sage: P3D.show() # long time, optional - sage.plot :: sage: G = graphs.PetersenGraph() - sage: G.plot3d(engine='tachyon', vertex_colors={(0,0,1): list(G)}).show() # long time + sage: G.plot3d(engine='tachyon', # long time, optional - sage.plot + ....: vertex_colors={(0,0,1): list(G)}).show() :: sage: C = graphs.CubeGraph(4) - sage: C.plot3d(engine='tachyon', edge_colors={(0,1,0): C.edges(sort=False)}, vertex_colors={(1,1,1): list(C)}, bgcolor=(0,0,0)).show() # long time + sage: C.plot3d(engine='tachyon', # long time, optional - sage.plot + ....: edge_colors={(0,1,0): C.edges(sort=False)}, + ....: vertex_colors={(1,1,1): list(C)}, bgcolor=(0,0,0)).show() :: sage: K = graphs.CompleteGraph(3) - sage: K.plot3d(engine='tachyon', edge_colors={(1,0,0): [(0,1,None)], (0,1,0): [(0,2,None)], (0,0,1): [(1,2,None)]}).show() # long time + sage: K.plot3d(engine='tachyon', # long time, optional - sage.plot + ....: edge_colors={(1,0,0): [(0,1,None)], + ....: (0,1,0): [(0,2,None)], + ....: (0,0,1): [(1,2,None)]}).show() A directed version of the dodecahedron @@ -20969,7 +20989,7 @@ def plot3d(self, bgcolor=(1, 1, 1), ....: 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: []}) - sage: D.plot3d().show() # long time + sage: D.plot3d().show() # long time, optional - sage.plot :: @@ -20977,12 +20997,13 @@ def plot3d(self, bgcolor=(1, 1, 1), sage: from sage.plot.colors import rainbow sage: R = rainbow(P.size(), 'rgbtuple') sage: edge_colors = {R[i]: [e] for i, e in enumerate(P.edge_iterator())} - sage: P.plot3d(engine='tachyon', edge_colors=edge_colors).show() # long time + sage: P.plot3d(engine='tachyon', edge_colors=edge_colors).show() # long time, optional - sage.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 = Graph({'a': ['a','b','b','b','e'], 'b': ['c','d','e'], + ....: 'c': ['c','d','d','d'], 'd': ['e']}, sparse=True) sage: G.show3d() Traceback (most recent call last): ... @@ -20991,23 +21012,24 @@ def plot3d(self, bgcolor=(1, 1, 1), Using the ``partition`` keyword:: sage: G = graphs.WheelGraph(7) - sage: G.plot3d(partition=[[0], [1, 2, 3, 4, 5, 6]]) + sage: G.plot3d(partition=[[0], [1, 2, 3, 4, 5, 6]]) # optional - sage.plot Graphics3d Object TESTS:: sage: G = DiGraph({0: {1: 'a', 2: 'a'}, 1: {0: 'b'}, 2: {0: 'c'}}) - sage: p = G.plot3d(edge_labels=True, color_by_label={'a': 'yellow', 'b': 'cyan'}) - sage: s = p.x3d_str() + sage: p = G.plot3d(edge_labels=True, # optional - sage.plot + ....: color_by_label={'a': 'yellow', 'b': 'cyan'}) + sage: s = p.x3d_str() # optional - sage.plot This 3D plot contains four yellow objects (two cylinders and two cones), two black objects and 2 cyan objects:: - sage: s.count("Material diffuseColor='1.0 1.0 0.0'") + sage: s.count("Material diffuseColor='1.0 1.0 0.0'") # optional - sage.plot 4 - sage: s.count("Material diffuseColor='0.0 0.0 0.0'") + sage: s.count("Material diffuseColor='0.0 0.0 0.0'") # optional - sage.plot 2 - sage: s.count("Material diffuseColor='0.0 1.0 1.0'") + sage: s.count("Material diffuseColor='0.0 1.0 1.0'") # optional - sage.plot 2 .. SEEALSO:: @@ -21176,36 +21198,43 @@ def show3d(self, bgcolor=(1, 1, 1), vertex_colors=None, vertex_size=0.06, EXAMPLES:: sage: G = graphs.CubeGraph(5) - sage: G.show3d(iterations=500, edge_size=None, vertex_size=0.04) # long time + sage: G.show3d(iterations=500, edge_size=None, vertex_size=0.04) # long time, optional - sage.plot We plot a fairly complicated Cayley graph:: sage: A5 = AlternatingGroup(5); A5 Alternating group of order 5!/2 as a permutation group sage: G = A5.cayley_graph() - sage: G.show3d(vertex_size=0.03, edge_size=0.01, edge_size2=0.02, # long time + sage: G.show3d(vertex_size=0.03, # long time, optional - sage.plot + ....: edge_size=0.01, edge_size2=0.02, ....: vertex_colors={(1,1,1): list(G)}, bgcolor=(0,0,0), ....: color_by_label=True, iterations=200) Some :class:`~sage.plot.plot3d.tachyon.Tachyon` examples:: sage: D = graphs.DodecahedralGraph() - sage: D.show3d(engine='tachyon') # long time + sage: D.show3d(engine='tachyon') # long time, optional - sage.plot :: sage: G = graphs.PetersenGraph() - sage: G.show3d(engine='tachyon', vertex_colors={(0,0,1): list(G)}) # long time + sage: G.show3d(engine='tachyon', # long time, optional - sage.plot + ....: vertex_colors={(0,0,1): list(G)}) :: sage: C = graphs.CubeGraph(4) - sage: C.show3d(engine='tachyon', edge_colors={(0,1,0): C.edges(sort=False)}, vertex_colors={(1,1,1): list(C)}, bgcolor=(0,0,0)) # long time + sage: C.show3d(engine='tachyon', # long time, optional - sage.plot + ....: edge_colors={(0,1,0): C.edges(sort=False)}, + ....: vertex_colors={(1,1,1): list(C)}, bgcolor=(0,0,0)) :: sage: K = graphs.CompleteGraph(3) - sage: K.show3d(engine='tachyon', edge_colors={(1,0,0): [(0, 1, None)], (0, 1, 0): [(0, 2, None)], (0, 0, 1): [(1, 2, None)]}) # long time + sage: K.show3d(engine='tachyon', # long time, optional - sage.plot + ....: edge_colors={(1,0,0): [(0, 1, None)], + ....: (0, 1, 0): [(0, 2, None)], + ....: (0, 0, 1): [(1, 2, None)]}) """ self.plot3d(bgcolor=bgcolor, vertex_colors=vertex_colors, edge_colors=edge_colors, vertex_size=vertex_size, engine=engine, @@ -21312,7 +21341,9 @@ def graphviz_string(self, **options): EXAMPLES:: - sage: G = Graph({0: {1: None, 2: None}, 1: {0: None, 2: None}, 2: {0: None, 1: None, 3: 'foo'}, 3: {2: 'foo'}}, sparse=True) + sage: G = Graph({0: {1: None, 2: None}, 1: {0: None, 2: None}, + ....: 2: {0: None, 1: None, 3: 'foo'}, 3: {2: 'foo'}}, + ....: sparse=True) sage: print(G.graphviz_string(edge_labels=True)) graph { node_0 [label="0"]; @@ -21345,7 +21376,8 @@ def graphviz_string(self, **options): Same, with a digraph and a color for edges:: - sage: G = DiGraph({0: {1: None, 2: None}, 1: {2: None}, 2: {3: 'foo'}, 3: {}}, sparse=True) + sage: G = DiGraph({0: {1: None, 2: None}, 1: {2: None}, 2: {3: 'foo'}, 3: {}}, + ....: sparse=True) sage: print(G.graphviz_string(edge_color="red")) digraph { node_0 [label="0"]; @@ -21362,12 +21394,13 @@ def graphviz_string(self, **options): A digraph using latex labels for vertices and edges:: - sage: f(x) = -1 / x # optional - sage.symbolic - sage: g(x) = 1 / (x + 1) # optional - sage.symbolic - sage: G = DiGraph() # optional - sage.symbolic - sage: G.add_edges((i, f(i), f) for i in (1, 2, 1/2, 1/4)) # optional - sage.symbolic - sage: G.add_edges((i, g(i), g) for i in (1, 2, 1/2, 1/4)) # optional - sage.symbolic - sage: print(G.graphviz_string(labels="latex", edge_labels=True)) # random # optional - sage.symbolic + sage: f(x) = -1 / x # optional - sage.symbolic + sage: g(x) = 1 / (x + 1) # optional - sage.symbolic + sage: G = DiGraph() # optional - sage.symbolic + sage: G.add_edges((i, f(i), f) for i in (1, 2, 1/2, 1/4)) # optional - sage.symbolic + sage: G.add_edges((i, g(i), g) for i in (1, 2, 1/2, 1/4)) # optional - sage.symbolic + sage: print(G.graphviz_string(labels="latex", # random # optional - sage.symbolic + ....: edge_labels=True)) digraph { node [shape="plaintext"]; node_10 [label=" ", texlbl="$1$"]; @@ -21393,7 +21426,8 @@ def graphviz_string(self, **options): node_4 -> node_9 [label=" ", texlbl="$x \ {\mapsto}\ \frac{1}{x + 1}$"]; } - sage: print(G.graphviz_string(labels="latex", color_by_label=True)) # random # optional - sage.symbolic + sage: print(G.graphviz_string(labels="latex", # random # optional - sage.symbolic + ....: color_by_label=True)) digraph { node [shape="plaintext"]; node_10 [label=" ", texlbl="$1$"]; @@ -21419,7 +21453,8 @@ def graphviz_string(self, **options): node_4 -> node_9 [color = "#00ffff"]; } - sage: print(G.graphviz_string(labels="latex", color_by_label={f: "red", g: "blue"})) # random # optional - sage.symbolic + sage: print(G.graphviz_string(labels="latex", # random # optional - sage.symbolic + ....: color_by_label={f: "red", g: "blue"})) digraph { node [shape="plaintext"]; node_10 [label=" ", texlbl="$1$"]; @@ -21506,7 +21541,7 @@ def graphviz_string(self, **options): sage: def edge_options(data): ....: u, v, label = data ....: return {"dir":"back"} if u == 1 else {} - sage: print(G.graphviz_string(edge_options=edge_options)) # random # optional - sage.symbolic + sage: print(G.graphviz_string(edge_options=edge_options)) # random # optional - sage.symbolic digraph { node_0 [label="-1"]; node_1 [label="-1/2"]; @@ -21540,7 +21575,7 @@ def graphviz_string(self, **options): ....: if (u,v) == (1, -1): options["label_style"] = "latex" ....: if (u,v) == (1, 1/2): options["dir"] = "back" ....: return options - sage: print(G.graphviz_string(edge_options=edge_options)) # random # optional - sage.symbolic + sage: print(G.graphviz_string(edge_options=edge_options)) # random # optional - sage.symbolic digraph { node_0 [label="-1"]; node_1 [label="-1/2"]; @@ -21906,7 +21941,9 @@ def graphviz_to_file_named(self, filename, **options): EXAMPLES:: - sage: G = Graph({0: {1: None, 2: None}, 1: {0: None, 2: None}, 2: {0: None, 1: None, 3: 'foo'}, 3: {2: 'foo'}}, sparse=True) + sage: G = Graph({0: {1: None, 2: None}, 1: {0: None, 2: None}, + ....: 2: {0: None, 1: None, 3: 'foo'}, 3: {2: 'foo'}}, + ....: sparse=True) sage: import tempfile sage: with tempfile.NamedTemporaryFile(mode="a+t") as f: ....: G.graphviz_to_file_named(f.name, edge_labels=True) @@ -22184,22 +22221,22 @@ def eigenspaces(self, laplacian=False): sage: P = graphs.PetersenGraph() sage: P.eigenspaces() [ - (3, Vector space of degree 10 and dimension 1 over Rational Field - User basis matrix: - [1 1 1 1 1 1 1 1 1 1]), + (3, Vector space of degree 10 and dimension 1 over Rational Field + User basis matrix: + [1 1 1 1 1 1 1 1 1 1]), (-2, Vector space of degree 10 and dimension 4 over Rational Field - User basis matrix: - [ 1 0 0 0 -1 -1 -1 0 1 1] - [ 0 1 0 0 -1 0 -2 -1 1 2] - [ 0 0 1 0 -1 1 -1 -2 0 2] - [ 0 0 0 1 -1 1 0 -1 -1 1]), - (1, Vector space of degree 10 and dimension 5 over Rational Field - User basis matrix: - [ 1 0 0 0 0 1 -1 0 0 -1] - [ 0 1 0 0 0 -1 1 -1 0 0] - [ 0 0 1 0 0 0 -1 1 -1 0] - [ 0 0 0 1 0 0 0 -1 1 -1] - [ 0 0 0 0 1 -1 0 0 -1 1]) + User basis matrix: + [ 1 0 0 0 -1 -1 -1 0 1 1] + [ 0 1 0 0 -1 0 -2 -1 1 2] + [ 0 0 1 0 -1 1 -1 -2 0 2] + [ 0 0 0 1 -1 1 0 -1 -1 1]), + (1, Vector space of degree 10 and dimension 5 over Rational Field + User basis matrix: + [ 1 0 0 0 0 1 -1 0 0 -1] + [ 0 1 0 0 0 -1 1 -1 0 0] + [ 0 0 1 0 0 0 -1 1 -1 0] + [ 0 0 0 1 0 0 0 -1 1 -1] + [ 0 0 0 0 1 -1 0 0 -1 1]) ] Eigenspaces for the Laplacian should be identical since the Petersen @@ -22209,21 +22246,21 @@ def eigenspaces(self, laplacian=False): sage: P.eigenspaces(laplacian=True) [ (0, Vector space of degree 10 and dimension 1 over Rational Field - User basis matrix: - [1 1 1 1 1 1 1 1 1 1]), + User basis matrix: + [1 1 1 1 1 1 1 1 1 1]), (5, Vector space of degree 10 and dimension 4 over Rational Field - User basis matrix: - [ 1 0 0 0 -1 -1 -1 0 1 1] - [ 0 1 0 0 -1 0 -2 -1 1 2] - [ 0 0 1 0 -1 1 -1 -2 0 2] - [ 0 0 0 1 -1 1 0 -1 -1 1]), + User basis matrix: + [ 1 0 0 0 -1 -1 -1 0 1 1] + [ 0 1 0 0 -1 0 -2 -1 1 2] + [ 0 0 1 0 -1 1 -1 -2 0 2] + [ 0 0 0 1 -1 1 0 -1 -1 1]), (2, Vector space of degree 10 and dimension 5 over Rational Field - User basis matrix: - [ 1 0 0 0 0 1 -1 0 0 -1] - [ 0 1 0 0 0 -1 1 -1 0 0] - [ 0 0 1 0 0 0 -1 1 -1 0] - [ 0 0 0 1 0 0 0 -1 1 -1] - [ 0 0 0 0 1 -1 0 0 -1 1]) + User basis matrix: + [ 1 0 0 0 0 1 -1 0 0 -1] + [ 0 1 0 0 0 -1 1 -1 0 0] + [ 0 0 1 0 0 0 -1 1 -1 0] + [ 0 0 0 1 0 0 0 -1 1 -1] + [ 0 0 0 0 1 -1 0 0 -1 1]) ] Notice how one eigenspace below is described with a square root of 2. @@ -22233,20 +22270,21 @@ def eigenspaces(self, laplacian=False): sage: C = graphs.CycleGraph(8) sage: C.eigenspaces() [ - (2, Vector space of degree 8 and dimension 1 over Rational Field - User basis matrix: - [1 1 1 1 1 1 1 1]), + (2, Vector space of degree 8 and dimension 1 over Rational Field + User basis matrix: + [1 1 1 1 1 1 1 1]), (-2, Vector space of degree 8 and dimension 1 over Rational Field - User basis matrix: - [ 1 -1 1 -1 1 -1 1 -1]), - (0, Vector space of degree 8 and dimension 2 over Rational Field - User basis matrix: - [ 1 0 -1 0 1 0 -1 0] - [ 0 1 0 -1 0 1 0 -1]), - (a3, Vector space of degree 8 and dimension 2 over Number Field in a3 with defining polynomial x^2 - 2 - User basis matrix: - [ 1 0 -1 -a3 -1 0 1 a3] - [ 0 1 a3 1 0 -1 -a3 -1]) + User basis matrix: + [ 1 -1 1 -1 1 -1 1 -1]), + (0, Vector space of degree 8 and dimension 2 over Rational Field + User basis matrix: + [ 1 0 -1 0 1 0 -1 0] + [ 0 1 0 -1 0 1 0 -1]), + (a3, Vector space of degree 8 and dimension 2 over + Number Field in a3 with defining polynomial x^2 - 2 + User basis matrix: + [ 1 0 -1 -a3 -1 0 1 a3] + [ 0 1 a3 1 0 -1 -a3 -1]) ] A digraph may have complex eigenvalues and eigenvectors. For a 3-cycle, @@ -22255,12 +22293,13 @@ def eigenspaces(self, laplacian=False): sage: T = DiGraph({0: [1], 1: [2], 2: [0]}) sage: T.eigenspaces() [ - (1, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [1 1 1]), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 + x + 1 - User basis matrix: - [ 1 a1 -a1 - 1]) + (1, Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [1 1 1]), + (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 + with defining polynomial x^2 + x + 1 + User basis matrix: + [ 1 a1 -a1 - 1]) ] """ if laplacian: @@ -22348,7 +22387,7 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input=True, c vertices have an image can require some time, and this feature can be disabled (at your own risk):: - sage: G.relabel({1:2,2:1}, inplace=False, complete_partial_function = False).am() + sage: G.relabel({1:2,2:1}, inplace=False, complete_partial_function=False).am() Traceback (most recent call last): ... KeyError: 0 @@ -22370,10 +22409,10 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input=True, c Relabeling using a Sage permutation:: sage: G = graphs.PathGraph(3) - sage: from sage.groups.perm_gps.permgroup_named import SymmetricGroup # optional - sage.groups - sage: S = SymmetricGroup(3) # optional - sage.groups - sage: gamma = S('(1,2)') # optional - sage.groups - sage: G.relabel(gamma, inplace=False).am() # optional - sage.groups + sage: from sage.groups.perm_gps.permgroup_named import SymmetricGroup # optional - sage.groups + sage: S = SymmetricGroup(3) # optional - sage.groups + sage: gamma = S('(1,2)') # optional - sage.groups + sage: G.relabel(gamma, inplace=False).am() # optional - sage.groups [0 0 1] [0 0 1] [1 1 0] @@ -22668,7 +22707,8 @@ def is_equitable(self, partition, quotient_matrix=False): sage: ss.is_equitable(prt) Traceback (most recent call last): ... - TypeError: Partition ([[(0, 1)], [(0, 2), (0, 3), (0, 4), (1, 2), (1, 4)], [(2, 3), (3, 4)]]) is not valid for this graph: vertices are incorrect. + TypeError: Partition ([[(0, 1)], [(0, 2), (0, 3), (0, 4), (1, 2), (1, 4)], + [(2, 3), (3, 4)]]) is not valid for this graph: vertices are incorrect. :: @@ -22753,7 +22793,8 @@ def coarsest_equitable_refinement(self, partition, sparse=True): sage: ss.coarsest_equitable_refinement(prt) Traceback (most recent call last): ... - TypeError: partition ([[(0, 1)], [(0, 2), (0, 3), (0, 4), (1, 2), (1, 4)], [(2, 3), (3, 4)]]) is not valid for this graph: vertices are incorrect + TypeError: partition ([[(0, 1)], [(0, 2), (0, 3), (0, 4), (1, 2), (1, 4)], + [(2, 3), (3, 4)]]) is not valid for this graph: vertices are incorrect :: @@ -22807,25 +22848,25 @@ def automorphism_group(self, partition=None, verbosity=0, INPUT: - - ``partition`` - default is the unit partition, + - ``partition`` -- default is the unit partition, otherwise computes the subgroup of the full automorphism group respecting the partition. - - ``edge_labels`` - default False, otherwise allows + - ``edge_labels`` -- default ``False``, otherwise allows only permutations respecting edge labels. - - ``order`` - (default False) if True, compute the + - ``order`` -- (default ``False``) if ``True``, compute the order of the automorphism group - - ``return_group`` - default True + - ``return_group`` -- default ``True`` - - ``orbits`` - returns the orbits of the group acting + - ``orbits`` -- returns the orbits of the group acting on the vertices of the graph - - ``algorithm`` - If ``algorithm = "bliss"`` the automorphism group is + - ``algorithm`` -- If ``algorithm = "bliss"``, the automorphism group is computed using the optional package bliss (http://www.tcs.tkk.fi/Software/bliss/index.html). Setting it to - "sage" uses Sage's implementation. If set to ``None`` (default), bliss + ``"sage"`` uses Sage's implementation. If set to ``None`` (default), bliss is used when available. OUTPUT: The order of the output is group, order, orbits. However, there @@ -22837,7 +22878,7 @@ def automorphism_group(self, partition=None, verbosity=0, sage: graphs_query = GraphQuery(display_cols=['graph6'],num_vertices=4) sage: L = graphs_query.get_graphs_list() - sage: graphs_list.show_graphs(L) + sage: graphs_list.show_graphs(L) # optional - sage.plot sage: for g in L: ....: G = g.automorphism_group() ....: G.order(), G.gens() @@ -22926,14 +22967,14 @@ def automorphism_group(self, partition=None, verbosity=0, :: sage: G = graphs.PetersenGraph() - sage: G.automorphism_group(return_group=False, orbits=True,algorithm='sage') + sage: G.automorphism_group(return_group=False, orbits=True, algorithm='sage') [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] sage: orb = G.automorphism_group(partition=[[0],list(range(1,10))], - ....: return_group=False, orbits=True,algorithm='sage') + ....: return_group=False, orbits=True, algorithm='sage') sage: sorted([sorted(o) for o in orb], key=len) [[0], [1, 4, 5], [2, 3, 6, 7, 8, 9]] sage: C = graphs.CubeGraph(3) - sage: orb = C.automorphism_group(orbits=True, return_group=False,algorithm='sage') + sage: orb = C.automorphism_group(orbits=True, return_group=False, algorithm='sage') sage: [sorted(o) for o in orb] [['000', '001', '010', '011', '100', '101', '110', '111']] @@ -23888,16 +23929,16 @@ def is_cayley(self, return_group=False, mapping=False, INPUT: - - ``return_group`` (boolean; ``False``) -- If True, return a group for + - ``return_group`` (boolean; ``False``) -- If ``True``, return a group for which the graph is a Cayley graph. - - ``mapping`` (boolean; ``False``) -- If True, return a mapping from + - ``mapping`` (boolean; ``False``) -- If ``True``, return a mapping from vertices to group elements. - - ``generators`` (boolean; ``False``) -- If True, return the generating + - ``generators`` (boolean; ``False``) -- If ``True``, return the generating set of the Cayley graph. - - ``allow_disconnected`` (boolean; ``False``) -- If True, disconnected + - ``allow_disconnected`` (boolean; ``False``) -- If ``True``, disconnected graphs are considered Cayley if they can be obtained from the Cayley construction with a generating set that does not generate the group. @@ -24320,7 +24361,8 @@ def katz_centrality(self, alpha, u=None): the Katz centrality value as `0`, as these nodes are not influenced by other nodes. :: - sage: G = DiGraph({1: [10], 2:[10,11], 3:[10,11], 4:[], 5:[11, 4], 6:[11], 7:[10,11], 8:[10,11], 9:[10], 10:[11, 5, 8], 11:[6]}) + sage: G = DiGraph({1: [10], 2:[10,11], 3:[10,11], 4:[], 5:[11, 4], 6:[11], + ....: 7:[10,11], 8:[10,11], 9:[10], 10:[11, 5, 8], 11:[6]}) sage: G.katz_centrality(.85) # rel tol 1e-14 {1: 0.000000000000000, 2: 0.000000000000000, @@ -24622,10 +24664,10 @@ def tachyon_vertex_plot(g, bgcolor=(1, 1, 1), sage: G = graphs.TetrahedralGraph() sage: from sage.graphs.generic_graph import tachyon_vertex_plot - sage: T,p = tachyon_vertex_plot(G, pos3d=G.layout(dim=3)) - sage: type(T) + sage: T,p = tachyon_vertex_plot(G, pos3d=G.layout(dim=3)) # optional - sage.plot + sage: type(T) # optional - sage.plot - sage: type(p) + sage: type(p) # optional - sage.plot <... 'dict'> """ assert pos3d is not None @@ -24766,7 +24808,8 @@ def graph_isom_equivalent_non_edge_labeled_graph(g, partition=None, standard_lab sage: g.edges(sort=True) [(0, 3, None), (1, 4, None), (2, 4, None), (2, 5, None), (3, 5, None)] - sage: g = graph_isom_equivalent_non_edge_labeled_graph(G,standard_label='string',return_edge_labels=True) + sage: g = graph_isom_equivalent_non_edge_labeled_graph(G, standard_label='string', + ....: return_edge_labels=True) sage: g[0] Graph on 6 vertices sage: g[0].edges(sort=True) diff --git a/src/sage/graphs/generic_graph_pyx.pyx b/src/sage/graphs/generic_graph_pyx.pyx index 022c02c3b06..712c2d955f0 100644 --- a/src/sage/graphs/generic_graph_pyx.pyx +++ b/src/sage/graphs/generic_graph_pyx.pyx @@ -399,7 +399,7 @@ cdef inline double sqrt_approx(double x, double y, double xx, double yy): ....: y = abs(y) ....: return max(x,y) + min(x,y)**2/(2*max(x,y)) - sage: polar_plot([1,lambda x:dist(cos(x),sin(x))], (0, 2*math.pi)) + sage: polar_plot([1,lambda x:dist(cos(x),sin(x))], (0, 2*math.pi)) # optional - sage.plot Graphics object consisting of 2 graphics primitives """ if xx < yy: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 7a3af39e4d2..b351b8501c0 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -106,7 +106,7 @@ 5: [7, 8], 6: [8,9], 7: [9]} sage: G = Graph(d); G Graph on 10 vertices - sage: G.plot().show() # or G.show() + sage: G.plot().show() # or G.show() # optional - sage.plot - A NetworkX graph: @@ -125,7 +125,7 @@ sage: s = ':I`AKGsaOs`cI]Gb~' sage: G = Graph(s, sparse=True); G Looped multi-graph on 10 vertices - sage: G.plot().show() # or G.show() + sage: G.plot().show() # or G.show() # optional - sage.plot Note that the ``\`` character is an escape character in Python, and also a character used by graph6 strings: @@ -142,7 +142,7 @@ :: sage: G = Graph('Ihe\\n@GUA') - sage: G.plot().show() # or G.show() + sage: G.plot().show() # or G.show() # optional - sage.plot - adjacency matrix: In an adjacency matrix, each column and each row represent a vertex. If a 1 shows up in row `i`, column `j`, there is an edge `(i,j)`. @@ -166,7 +166,7 @@ [0 0 0 0 1 0 1 1 0 0] sage: G = Graph(M); G Graph on 10 vertices - sage: G.plot().show() # or G.show() + sage: G.plot().show() # or G.show() # optional - sage.plot - incidence matrix: In an incidence matrix, each row represents a vertex and each column represents an edge. @@ -196,7 +196,7 @@ [ 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 1] sage: G = Graph(M); G Graph on 10 vertices - sage: G.plot().show() # or G.show() + sage: G.plot().show() # or G.show() # optional - sage.plot sage: DiGraph(matrix(2,[0,0,-1,1]), format="incidence_matrix") Traceback (most recent call last): ... @@ -254,7 +254,7 @@ :: sage: G = graphs.PetersenGraph() - sage: G.plot().show() # or G.show() + sage: G.plot().show() # or G.show() # optional - sage.plot sage: G.degree_histogram() [0, 0, 0, 10] sage: G.adjacency_matrix() @@ -272,7 +272,7 @@ :: sage: S = G.subgraph([0,1,2,3]) - sage: S.plot().show() # or S.show() + sage: S.plot().show() # or S.show() # optional - sage.plot sage: S.density() 1/2 @@ -280,7 +280,7 @@ sage: G = GraphQuery(display_cols=['graph6'], num_vertices=7, diameter=5) sage: L = G.get_graphs_list() - sage: graphs_list.show_graphs(L) + sage: graphs_list.show_graphs(L) # optional - sage.plot .. _Graph:labels: @@ -349,7 +349,7 @@ Show each graph as you iterate through the results:: - sage: for g in Q: + sage: for g in Q: # optional - sage.plot ....: show(g) Visualization @@ -359,11 +359,11 @@ view the graph in two dimensions via matplotlib with ``show()``. :: sage: G = graphs.RandomGNP(15,.3) - sage: G.show() + sage: G.show() # optional - sage.plot And you can view it in three dimensions via jmol with ``show3d()``. :: - sage: G.show3d() + sage: G.show3d() # optional - sage.plot Or it can be rendered with `\LaTeX`. This requires the right additions to a standard `\mbox{\rm\TeX}` installation. Then standard Sage commands, such as @@ -3855,14 +3855,14 @@ def coloring(self, algorithm="DLX", hex_colors=False, solver=None, verbose=0, True sage: are_equal_colorings(P, Q) True - sage: G.plot(partition=P) + sage: G.plot(partition=P) # optional - sage.plot Graphics object consisting of 16 graphics primitives sage: G.coloring(hex_colors=True, algorithm="MILP") {'#0000ff': [4], '#00ff00': [0, 6, 5], '#ff0000': [2, 1, 3]} sage: H = G.coloring(hex_colors=True, algorithm="DLX") sage: H {'#0000ff': [4], '#00ff00': [1, 2, 3], '#ff0000': [0, 5, 6]} - sage: G.plot(vertex_colors=H) + sage: G.plot(vertex_colors=H) # optional - sage.plot Graphics object consisting of 16 graphics primitives .. PLOT:: @@ -5949,13 +5949,13 @@ def to_directed(self, data_structure=None, sparse=None): :trac:`22424`:: - sage: G1=graphs.RandomGNP(5,0.5) - sage: gp1 = G1.graphplot(save_pos=True) - sage: G2=G1.to_directed() + sage: G1 = graphs.RandomGNP(5,0.5) + sage: gp1 = G1.graphplot(save_pos=True) # optional - sage.plot + sage: G2 = G1.to_directed() sage: G2.delete_vertex(0) sage: G2.add_vertex(5) - sage: gp2 = G2.graphplot() - sage: gp1 = G1.graphplot() + sage: gp2 = G2.graphplot() # optional - sage.plot + sage: gp1 = G1.graphplot() # optional - sage.plot Vertex labels will be retained (:trac:`14708`):: @@ -6545,7 +6545,7 @@ def cliques_maximal(self, algorithm="native"): [2, 6], [2, 8], [3, 4], [3, 7], [3, 9], [4, 5], [4, 8], [5, 10], [5, 11], [6, 10], [6, 11], [7, 8], [7, 11], [8, 10], [9, 10], [9, 11]] sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2, 2]) + sage: G.show(figsize=[2, 2]) # optional - sage.plot sage: G.cliques_maximal() [[0, 1, 2], [0, 1, 3]] sage: C = graphs.PetersenGraph() @@ -6720,7 +6720,7 @@ def clique_number(self, algorithm="Cliquer", cliques=None, solver=None, verbose= sage: C.clique_number() 4 sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.clique_number() 3 @@ -6731,12 +6731,14 @@ def clique_number(self, algorithm="Cliquer", cliques=None, solver=None, verbose= A non-empty graph without edges has a clique number of 1:: - sage: all((i*graphs.CompleteGraph(1)).clique_number() == 1 for i in range(1,15)) + sage: all((i*graphs.CompleteGraph(1)).clique_number() == 1 + ....: for i in range(1,15)) True A complete multipartite graph with k parts has clique number k:: - sage: all((i*graphs.CompleteMultipartiteGraph(i*[5])).clique_number() == i for i in range(1,6)) + sage: all((i*graphs.CompleteMultipartiteGraph(i*[5])).clique_number() == i + ....: for i in range(1,6)) True TESTS:: @@ -6802,7 +6804,7 @@ def cliques_number_of(self, vertices=None, cliques=None): sage: F.cliques_number_of(vertices=(0, 1)) 3 sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.cliques_number_of() {0: 2, 1: 2, 2: 1, 3: 1} """ @@ -6838,14 +6840,14 @@ def cliques_get_max_clique_graph(self): EXAMPLES:: - sage: (graphs.ChvatalGraph()).cliques_get_max_clique_graph() + sage: MCG = graphs.ChvatalGraph().cliques_get_max_clique_graph(); MCG Graph on 24 vertices - sage: ((graphs.ChvatalGraph()).cliques_get_max_clique_graph()).show(figsize=[2,2], vertex_size=20, vertex_labels=False) + sage: MCG.show(figsize=[2,2], vertex_size=20, vertex_labels=False) # optional - sage.plot sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.cliques_get_max_clique_graph() Graph on 2 vertices - sage: (G.cliques_get_max_clique_graph()).show(figsize=[2,2]) + sage: G.cliques_get_max_clique_graph().show(figsize=[2,2]) # optional - sage.plot """ import networkx return Graph(networkx.make_max_clique_graph(self.networkx_graph(), create_using=networkx.MultiGraph()), @@ -6866,14 +6868,14 @@ def cliques_get_clique_bipartite(self, **kwds): EXAMPLES:: - sage: (graphs.ChvatalGraph()).cliques_get_clique_bipartite() + sage: CBG = graphs.ChvatalGraph().cliques_get_clique_bipartite(); CBG Bipartite graph on 36 vertices - sage: ((graphs.ChvatalGraph()).cliques_get_clique_bipartite()).show(figsize=[2,2], vertex_size=20, vertex_labels=False) + sage: CBG.show(figsize=[2,2], vertex_size=20, vertex_labels=False) # optional - sage.plot sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.cliques_get_clique_bipartite() Bipartite graph on 6 vertices - sage: (G.cliques_get_clique_bipartite()).show(figsize=[2,2]) + sage: G.cliques_get_clique_bipartite().show(figsize=[2,2]) # optional - sage.plot """ from .bipartite_graph import BipartiteGraph import networkx @@ -7443,7 +7445,7 @@ def cliques_vertex_clique_number(self, algorithm="cliquer", vertices=None, .. NOTE:: - Currently only implemented for undirected graphs. Use to_undirected + Currently only implemented for undirected graphs. Use :meth:`to_undirected` to convert a digraph to an undirected graph. INPUT: @@ -7464,21 +7466,20 @@ def cliques_vertex_clique_number(self, algorithm="cliquer", vertices=None, EXAMPLES:: sage: C = Graph('DJ{') - sage: C.cliques_vertex_clique_number() + sage: C.cliques_vertex_clique_number() # optional - sage.plot {0: 2, 1: 4, 2: 4, 3: 4, 4: 4} - sage: E = C.cliques_maximal() - sage: E + sage: E = C.cliques_maximal(); E [[0, 4], [1, 2, 3, 4]] - sage: C.cliques_vertex_clique_number(cliques=E,algorithm="networkx") + sage: C.cliques_vertex_clique_number(cliques=E, algorithm="networkx") # optional - sage.plot {0: 2, 1: 4, 2: 4, 3: 4, 4: 4} sage: F = graphs.Grid2dGraph(2,3) - sage: F.cliques_vertex_clique_number(algorithm="networkx") + sage: F.cliques_vertex_clique_number(algorithm="networkx") # optional - sage.plot {(0, 0): 2, (0, 1): 2, (0, 2): 2, (1, 0): 2, (1, 1): 2, (1, 2): 2} - sage: F.cliques_vertex_clique_number(vertices=[(0, 1), (1, 2)]) + sage: F.cliques_vertex_clique_number(vertices=[(0, 1), (1, 2)]) # optional - sage.plot {(0, 1): 2, (1, 2): 2} sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) - sage: G.cliques_vertex_clique_number() + sage: G.show(figsize=[2,2]) # optional - sage.plot + sage: G.cliques_vertex_clique_number() # optional - sage.plot {0: 3, 1: 3, 2: 3, 3: 3} """ if algorithm == "cliquer": @@ -7539,7 +7540,7 @@ def cliques_containing_vertex(self, vertices=None, cliques=None): 4: [[0, 4], [1, 2, 3, 4]]} sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) - sage: G.show(figsize=[2,2]) + sage: G.show(figsize=[2,2]) # optional - sage.plot sage: G.cliques_containing_vertex() {0: [[0, 1, 2], [0, 1, 3]], 1: [[0, 1, 2], [0, 1, 3]], @@ -8568,7 +8569,7 @@ def two_factor_petersen(self, solver=None, verbose=0, *, integrality_tolerance=1 sage: g = graphs.CirculantGraph(24, [7, 11]) sage: cl = g.two_factor_petersen() - sage: g.plot(edge_colors={'black':cl[0], 'red':cl[1]}) + sage: g.plot(edge_colors={'black':cl[0], 'red':cl[1]}) # optional - sage.plot Graphics object consisting of 73 graphics primitives """ diff --git a/src/sage/graphs/graph_database.py b/src/sage/graphs/graph_database.py index a875f00396d..884ad87249c 100644 --- a/src/sage/graphs/graph_database.py +++ b/src/sage/graphs/graph_database.py @@ -121,7 +121,7 @@ def graph6_to_plot(graph6): EXAMPLES:: sage: from sage.graphs.graph_database import graph6_to_plot - sage: type(graph6_to_plot('D??')) + sage: type(graph6_to_plot('D??')) # optional - sage.plot """ g = Graph(str(graph6)) diff --git a/src/sage/graphs/graph_list.py b/src/sage/graphs/graph_list.py index d22a639adb9..ea84b183fb2 100644 --- a/src/sage/graphs/graph_list.py +++ b/src/sage/graphs/graph_list.py @@ -258,8 +258,8 @@ def to_graphics_array(graph_list, **kwds): sage: glist = [] sage: for i in range(999): ....: glist.append(graphs.RandomGNP(6, .45)) - sage: garray = graphs_list.to_graphics_array(glist) - sage: garray.nrows(), garray.ncols() + sage: garray = graphs_list.to_graphics_array(glist) # optional - sage.plot + sage: garray.nrows(), garray.ncols() # optional - sage.plot (250, 4) See the .plot() or .show() documentation for an individual graph for @@ -268,7 +268,7 @@ def to_graphics_array(graph_list, **kwds): sage: glist = [] sage: for _ in range(10): ....: glist.append(graphs.RandomLobster(41, .3, .4)) - sage: graphs_list.to_graphics_array(glist, layout='spring', vertex_size=20) + sage: graphs_list.to_graphics_array(glist, layout='spring', vertex_size=20) # optional - sage.plot Graphics Array of size 3 x 4 """ from sage.graphs import graph @@ -342,7 +342,7 @@ def show_graphs(graph_list, **kwds): Show the graphs in a graphics array:: - sage: graphs_list.show_graphs(glist) + sage: graphs_list.show_graphs(glist) # optional - sage.plot Example where more than one graphics array is used:: @@ -350,7 +350,7 @@ def show_graphs(graph_list, **kwds): sage: g = gq.get_graphs_list() sage: len(g) 34 - sage: graphs_list.show_graphs(g) + sage: graphs_list.show_graphs(g) # optional - sage.plot See the .plot() or .show() documentation for an individual graph for options, all of which are available from :func:`to_graphics_array`:: @@ -358,7 +358,7 @@ def show_graphs(graph_list, **kwds): sage: glist = [] sage: for _ in range(10): ....: glist.append(graphs.RandomLobster(41, .3, .4)) - sage: graphs_list.show_graphs(glist, layout='spring', vertex_size=20) + sage: graphs_list.show_graphs(glist, layout='spring', vertex_size=20) # optional - sage.plot """ graph_list = list(graph_list) for i in range(len(graph_list) // 20 + 1): diff --git a/src/sage/graphs/graph_plot.py b/src/sage/graphs/graph_plot.py index afe875945ff..0a7dbb81fc6 100644 --- a/src/sage/graphs/graph_plot.py +++ b/src/sage/graphs/graph_plot.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.plot r""" Graph plotting diff --git a/src/sage/graphs/graph_plot_js.py b/src/sage/graphs/graph_plot_js.py index cf7e37dce4b..44b6274cf4c 100644 --- a/src/sage/graphs/graph_plot_js.py +++ b/src/sage/graphs/graph_plot_js.py @@ -164,14 +164,15 @@ def gen_html_code(G, EXAMPLES:: - sage: graphs.RandomTree(50).show(method="js") # optional -- internet + sage: graphs.RandomTree(50).show(method="js") # optional -- internet sage.plot sage: g = graphs.PetersenGraph() - sage: g.show(method="js", vertex_partition=g.coloring()) # optional -- internet + sage: g.show(method="js", vertex_partition=g.coloring()) # optional -- internet sage.plot - sage: graphs.DodecahedralGraph().show(method="js", force_spring_layout=True) # optional -- internet + sage: graphs.DodecahedralGraph().show(method="js", # optional -- internet sage.plot + ....: force_spring_layout=True) - sage: graphs.DodecahedralGraph().show(method="js") # optional -- internet + sage: graphs.DodecahedralGraph().show(method="js") # optional -- internet sage.plot sage: g = digraphs.DeBruijn(2, 2) sage: g.allow_multiple_edges(True) @@ -180,7 +181,7 @@ def gen_html_code(G, sage: g.add_edge("10", "10", "c") sage: g.add_edge("10", "10", "d") sage: g.add_edge("01", "11", "1") - sage: g.show(method="js", vertex_labels=True,edge_labels=True, + sage: g.show(method="js", vertex_labels=True,edge_labels=True, # optional - sage.plot ....: link_distance=200, gravity=.05, charge=-500, ....: edge_partition=[[("11", "12", "2"), ("21", "21", "a")]], ....: edge_thickness=4) diff --git a/src/sage/graphs/hypergraph_generators.py b/src/sage/graphs/hypergraph_generators.py index e90beaee76d..a106f3fc7d8 100644 --- a/src/sage/graphs/hypergraph_generators.py +++ b/src/sage/graphs/hypergraph_generators.py @@ -355,7 +355,7 @@ def BinomialRandomUniform(self, n, k, p): raise ValueError("edge probability should be in [0,1]") import numpy.random as nrn - from sage.functions.other import binomial + from sage.arith.misc import binomial m = nrn.binomial(binomial(nverts, uniformity), p) return hypergraphs.UniformRandomUniform(n, k, m) diff --git a/src/sage/graphs/line_graph.pyx b/src/sage/graphs/line_graph.pyx index 9b0b1b6156a..25cd48de951 100644 --- a/src/sage/graphs/line_graph.pyx +++ b/src/sage/graphs/line_graph.pyx @@ -191,7 +191,7 @@ def is_line_graph(g, certificate=False): sage: is_line, R, isom = g.is_line_graph(certificate=True) sage: R.sparse6_string() ':DaHI~' - sage: R.show() + sage: R.show() # optional - sage.plot sage: isom {0: (0, 1), 1: (0, 2), 2: (1, 3), 3: (2, 3), 4: (3, 4)} diff --git a/src/sage/graphs/schnyder.py b/src/sage/graphs/schnyder.py index 8a33cc8c70e..5427a93691e 100644 --- a/src/sage/graphs/schnyder.py +++ b/src/sage/graphs/schnyder.py @@ -743,7 +743,7 @@ def minimal_schnyder_wood(graph, root_edge=None, minimal=True, check=True): sage: newg = minimal_schnyder_wood(g) sage: newg.edges(sort=True) [(0, -3, 'red'), (0, -2, 'blue'), (0, -1, 'green')] - sage: newg.plot(color_by_label={'red':'red','blue':'blue', + sage: newg.plot(color_by_label={'red':'red','blue':'blue', # optional - sage.plot ....: 'green':'green',None:'black'}) Graphics object consisting of 8 graphics primitives diff --git a/src/sage/graphs/spanning_tree.pyx b/src/sage/graphs/spanning_tree.pyx index 5c017314724..6880a787c8e 100644 --- a/src/sage/graphs/spanning_tree.pyx +++ b/src/sage/graphs/spanning_tree.pyx @@ -976,7 +976,7 @@ def random_spanning_tree(G, output_as_graph=False, by_weight=False, weight_funct sage: pos = G.get_pos() sage: T = G.random_spanning_tree(True) sage: T.set_pos(pos) - sage: T.show(vertex_labels=False) + sage: T.show(vertex_labels=False) # optional - sage.plot We can also use edge weights to change the probability of returning a spanning tree:: diff --git a/src/sage/graphs/tutte_polynomial.py b/src/sage/graphs/tutte_polynomial.py index 62d48f98c61..8f003084619 100644 --- a/src/sage/graphs/tutte_polynomial.py +++ b/src/sage/graphs/tutte_polynomial.py @@ -532,7 +532,7 @@ def tutte_polynomial(G, edge_selector=None, cache=None): The Tutte polynomial of any tree of order `n` is `x^{n-1}`:: - sage: all(T.tutte_polynomial() == x**9 for T in graphs.trees(10)) + sage: all(T.tutte_polynomial() == x**9 for T in graphs.trees(10)) # optional - sage.symbolic True The Tutte polynomial of the Petersen graph is:: @@ -560,7 +560,7 @@ def tutte_polynomial(G, edge_selector=None, cache=None): sage: G = graphs.OctahedralGraph() sage: T = G.tutte_polynomial() sage: R = PolynomialRing(ZZ, 'x') - sage: R((-1)^5*x*T(1-x,0)).factor() + sage: R((-1)^5*x*T(1-x,0)).factor() # optional - sage.symbolic (x - 2) * (x - 1) * x * (x^3 - 9*x^2 + 29*x - 32) sage: G.chromatic_polynomial().factor() (x - 2) * (x - 1) * x * (x^3 - 9*x^2 + 29*x - 32)