# Output of plantri and graphs.planar_graphs

I find the documentation of Sage much lacking what is the output of plantri and graphs.planar_graphs?

I assumed the output would be graphs (could not find documentation on this) and did the following

l = graphs.planar_graphs(4, dual=False)
gen = list(l)
ii = 1
G = gen[ii]
p = G.plot()
p.show()

edit retag close merge delete

Sort by » oldest newest most voted

The output of a command like graphs.planar_graphs(4) is an iterator that can yield all planar graphs with the specified number of vertices.

To get the documentation, do one of the following:

• in Sage, type graphs.planar_graph? and hit the return or enter key.

This will display the documentation for this function, in text mode.

• in Sage, type graphs.planar_graph?? and hit the return or enter key.

This will display the code source for this function, including the documentation string.

• in Sage, type browse_sage_doc(graphs.planar_graph).

This will open the documentation for this function, in html, in a browser tab.

• browse the online documentation:

So for example, if you define

sage: gen = graphs.planar_graphs(n)


and turn it into a list

sage: G = list(gen)


you could display a summary of this list of graphs and their diameters:

sage: newline = '\n'
sage: s = 'There are {} planar graphs on {} vertices.'
sage: s = s.format(n, len(G))
sage: for j, g in enumerate(G):
....:     s += newline + '{}.'.format(j)
....:     s += newline + 'Edges: {}'.format(g.edges(labels=False))
....:     s += newline + 'Diameter: {}'.format(g.diameter())
....:
sage: print(s)
There are 4 planar graphs on 6 vertices.
0.
Edges: [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
Diameter: 1
1.
Edges: [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4)]
Diameter: 2
2.
Edges: [(1, 2), (1, 3), (2, 4), (3, 4)]
Diameter: 2
3.
Edges: [(1, 2), (2, 3), (2, 4), (3, 4)]
Diameter: 2
4.
Edges: [(1, 2), (2, 3), (3, 4)]
Diameter: 3
5.
Edges: [(1, 2), (2, 3), (2, 4)]
Diameter: 2


or plot them all:

sage: for g in G:
....:     plot(g)
....:
Launched png viewer for Graphics object consisting of 11 graphics primitives
Launched png viewer for Graphics object consisting of 10 graphics primitives
Launched png viewer for Graphics object consisting of 9 graphics primitives
Launched png viewer for Graphics object consisting of 9 graphics primitives
Launched png viewer for Graphics object consisting of 8 graphics primitives
Launched png viewer for Graphics object consisting of 8 graphics primitives


etc.

Don't hesitate to suggest any specific improvement to the documentation.

more

To get the documentation on the function you mention, you do:

sage: graphs.planar_graphs?


which gives:

[...]

An iterator over connected planar graphs using the plantri
generator.

This uses the plantri generator (see [plantri]) which is available
through the optional package plantri.

Note: The non-3-connected graphs will be returned several times,
with all its possible embeddings.

[...]


You may also read the documentation of planar_graphs function online.

The output is not a graph, neither a list. It is an iterator of graphs.

more

Note about getting to know more about any function, method or module in Sage:

• graphs.planar_graphs? gives the documentation of graphs.planar_graphs
• help(graphs.planar_graphs) does the same
• graphs.planar_graphs?? gives the source code
• browse_sage_doc(graphs.planar_graphs) gives the documentation in html
• search_src('graphs.planar_graphs') looks for all occurrences in Sage's source code
• search_doc('graphs.planar_graphs') looks for all occurrences in Sage's documentation

For Python built-ins, such as for, while, if, use python_help, as in

python_help('if')


Thank both, but it doesn't quite answer my question what is the output of plantri and graphs.planar_graphs how come when I use the output as a graph I do not get a plot as usual? and I guess how to get a "graph" from a planar graph in the easiest way possible?