@@ -248,12 +248,12 @@ def CycleGraph(n):
248
248
249
249
Compare plotting using the predefined layout and networkx::
250
250
251
- sage: import networkx
252
- sage: n = networkx.cycle_graph(23)
253
- sage: spring23 = Graph(n)
254
- sage: posdict23 = graphs.CycleGraph(23)
255
- sage: spring23.show() # long time
256
- sage: posdict23.show() # long time
251
+ sage: import networkx # optional - networkx
252
+ sage: n = networkx.cycle_graph(23) # optional - networkx
253
+ sage: spring23 = Graph(n) # optional - networkx
254
+ sage: posdict23 = graphs.CycleGraph(23) # optional - networkx
255
+ sage: spring23.show() # long time # optional - networkx
256
+ sage: posdict23.show() # long time # optional - networkx
257
257
258
258
We next view many cycle graphs as a Sage graphics array. First we use the
259
259
``CycleGraph`` constructor, which fills in the position dictionary::
@@ -275,17 +275,17 @@ def CycleGraph(n):
275
275
276
276
sage: g = []
277
277
sage: j = []
278
- sage: for i in range(9):
278
+ sage: for i in range(9): # optional - networkx
279
279
....: spr = networkx.cycle_graph(i+3)
280
280
....: k = Graph(spr)
281
281
....: g.append(k)
282
- sage: for i in range(3):
282
+ sage: for i in range(3): # optional - networkx
283
283
....: n = []
284
284
....: for m in range(3):
285
285
....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False))
286
286
....: j.append(n)
287
- sage: G = graphics_array(j)
288
- sage: G.show() # long time
287
+ sage: G = graphics_array(j) # optional - networkx
288
+ sage: G.show() # long time # optional - networkx
289
289
290
290
TESTS:
291
291
@@ -349,27 +349,27 @@ def CompleteGraph(n):
349
349
350
350
We compare to plotting with the spring-layout algorithm::
351
351
352
- sage: import networkx
352
+ sage: import networkx # optional - networkx
353
353
sage: g = []
354
354
sage: j = []
355
- sage: for i in range(9):
355
+ sage: for i in range(9): # optional - networkx
356
356
....: spr = networkx.complete_graph(i+3)
357
357
....: k = Graph(spr)
358
358
....: g.append(k)
359
- sage: for i in range(3):
359
+ sage: for i in range(3): # optional - networkx
360
360
....: n = []
361
361
....: for m in range(3):
362
362
....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False))
363
363
....: j.append(n)
364
- sage: G = graphics_array(j)
365
- sage: G.show() # long time
364
+ sage: G = graphics_array(j) # optional - networkx
365
+ sage: G.show() # long time # optional - networkx
366
366
367
367
Compare the constructors (results will vary)::
368
368
369
- sage: import networkx
370
- sage: t = cputime()
371
- sage: n = networkx.complete_graph(389); spring389 = Graph(n)
372
- sage: cputime(t) # random
369
+ sage: import networkx # optional - networkx
370
+ sage: t = cputime() # optional - networkx
371
+ sage: n = networkx.complete_graph(389); spring389 = Graph(n) # optional - networkx
372
+ sage: cputime(t) # random # optional - networkx
373
373
0.59203700000000126
374
374
sage: t = cputime()
375
375
sage: posdict389 = graphs.CompleteGraph(389)
@@ -378,11 +378,11 @@ def CompleteGraph(n):
378
378
379
379
We compare plotting::
380
380
381
- sage: import networkx
382
- sage: n = networkx.complete_graph(23)
381
+ sage: import networkx # optional - networkx
382
+ sage: n = networkx.complete_graph(23) # optional - networkx
383
383
sage: spring23 = Graph(n)
384
384
sage: posdict23 = graphs.CompleteGraph(23)
385
- sage: spring23.show() # long time
385
+ sage: spring23.show() # long time # optional - networkx
386
386
sage: posdict23.show() # long time
387
387
"""
388
388
G = Graph (n , name = "Complete graph" )
@@ -438,19 +438,19 @@ def CompleteBipartiteGraph(p, q, set_position=True):
438
438
Two ways of constructing the complete bipartite graph, using different
439
439
layout algorithms::
440
440
441
- sage: import networkx
442
- sage: n = networkx.complete_bipartite_graph(389, 157); spring_big = Graph(n) # long time
441
+ sage: import networkx # optional - networkx
442
+ sage: n = networkx.complete_bipartite_graph(389, 157); spring_big = Graph(n) # long time # optional - networkx
443
443
sage: posdict_big = graphs.CompleteBipartiteGraph(389, 157) # long time
444
444
445
445
Compare the plotting::
446
446
447
- sage: n = networkx.complete_bipartite_graph(11, 17)
448
- sage: spring_med = Graph(n)
447
+ sage: n = networkx.complete_bipartite_graph(11, 17) # optional - networkx
448
+ sage: spring_med = Graph(n) # optional - networkx
449
449
sage: posdict_med = graphs.CompleteBipartiteGraph(11, 17)
450
450
451
451
Notice here how the spring-layout tends to center the nodes of `n1`::
452
452
453
- sage: spring_med.show() # long time
453
+ sage: spring_med.show() # long time # optional - networkx
454
454
sage: posdict_med.show() # long time
455
455
456
456
View many complete bipartite graphs with a Sage Graphics Array, with this
@@ -473,17 +473,17 @@ def CompleteBipartiteGraph(p, q, set_position=True):
473
473
474
474
sage: g = []
475
475
sage: j = []
476
- sage: for i in range(9):
476
+ sage: for i in range(9): # optional - networkx
477
477
....: spr = networkx.complete_bipartite_graph(i+1,4)
478
478
....: k = Graph(spr)
479
479
....: g.append(k)
480
- sage: for i in range(3):
480
+ sage: for i in range(3): # optional - networkx
481
481
....: n = []
482
482
....: for m in range(3):
483
483
....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False))
484
484
....: j.append(n)
485
- sage: G = graphics_array(j)
486
- sage: G.show() # long time
485
+ sage: G = graphics_array(j) # optional - networkx
486
+ sage: G.show() # long time # optional - networkx
487
487
488
488
:trac:`12155`::
489
489
@@ -933,9 +933,9 @@ def GridGraph(dim_list):
933
933
934
934
sage: dim = [randint(1,4) for i in range(4)]
935
935
sage: g = graphs.GridGraph(dim)
936
- sage: import networkx
937
- sage: h = Graph( networkx.grid_graph(list(dim)) )
938
- sage: g.is_isomorphic(h)
936
+ sage: import networkx # optional - networkx
937
+ sage: h = Graph(networkx.grid_graph(list(dim))) # optional - networkx
938
+ sage: g.is_isomorphic(h) # optional - networkx
939
939
True
940
940
941
941
Trivial cases::
@@ -1223,14 +1223,14 @@ def StarGraph(n):
1223
1223
1224
1224
EXAMPLES::
1225
1225
1226
- sage: import networkx
1226
+ sage: import networkx # optional - networkx
1227
1227
1228
1228
Compare the plots::
1229
1229
1230
- sage: n = networkx.star_graph(23)
1231
- sage: spring23 = Graph(n)
1230
+ sage: n = networkx.star_graph(23) # optional - networkx
1231
+ sage: spring23 = Graph(n) # optional - networkx
1232
1232
sage: posdict23 = graphs.StarGraph(23)
1233
- sage: spring23.show() # long time
1233
+ sage: spring23.show() # long time # optional - networkx
1234
1234
sage: posdict23.show() # long time
1235
1235
1236
1236
View many star graphs as a Sage Graphics Array
0 commit comments