8.1.2 Generators

If you wish to iterate through all the isomorphism types of graphs, type, for example:

sage: for g in graphs(4):
...     print g.spectrum()
[0.0, 0.0, 0.0, 0.0]
...
[-1.0, -1.0, -1.0, 3.0]

For some commonly used graphs to play with, type

sage: graphs.[tab]          # not tested

and hit tab. Most of these graphs come with their own custom plot, so you can see how people usually visualize these graphs.

sage: G = graphs.PetersenGraph()
sage: G.plot().show()    # or G.show()
sage: G.degree_histogram()
[0, 0, 0, 10]
sage: G.adjacency_matrix()
[0 1 0 0 1 1 0 0 0 0]
[1 0 1 0 0 0 1 0 0 0]
[0 1 0 1 0 0 0 1 0 0]
[0 0 1 0 1 0 0 0 1 0]
[1 0 0 1 0 0 0 0 0 1]
[1 0 0 0 0 0 0 1 1 0]
[0 1 0 0 0 0 0 0 1 1]
[0 0 1 0 0 1 0 0 0 1]
[0 0 0 1 0 1 1 0 0 0]
[0 0 0 0 1 0 1 1 0 0]

sage: S = G.subgraph([0,1,2,3])
sage: S.plot().show()    # or S.show()
sage: S.density()
1/2

sage: G = GraphDatabase()
sage: L = G.get_list(num_vertices=7, diameter=5)
sage: graphs_list.show_graphs(L)

See About this document... for information on suggesting changes.