ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 27 Jun 2018 12:37:43 +0200Output of plantri and graphs.planar_graphshttps://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_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()Fri, 25 May 2018 23:08:27 +0200https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/Answer by Sébastien for <p>I find the documentation of Sage much lacking what is the output of <code>plantri</code> and <code>graphs.planar_graphs</code>? </p>
<p>I assumed the output would be graphs (could not find documentation on this) and did the following</p>
<pre><code>l = graphs.planar_graphs(4, dual=False)
gen = list(l)
ii = 1
G = gen[ii]
p = G.plot()
p.show()
</code></pre>
https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?answer=42519#post-id-42519To 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](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_generators.html#sage.graphs.graph_generators.GraphGenerators.planar_graphs) function online.
The output is not a graph, neither a list. It is an *iterator* of graphs.Tue, 05 Jun 2018 22:35:38 +0200https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?answer=42519#post-id-42519Comment by slelievre for <p>To get the documentation on the function you mention, you do:</p>
<pre><code>sage: graphs.planar_graphs?
</code></pre>
<p>which gives:</p>
<pre><code>[...]
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.
[...]
</code></pre>
<p>You may also read the documentation of <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_generators.html#sage.graphs.graph_generators.GraphGenerators.planar_graphs">planar_graphs</a> function online.</p>
<p>The output is not a graph, neither a list. It is an <em>iterator</em> of graphs.</p>
https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?comment=42523#post-id-42523To learn more about iterators, you can go through the tutorial at
- [http://doc.sagemath.org/html/en/thematic_tutorials/tutorial-comprehensions.html](http://doc.sagemath.org/html/en/thematic_tutorials/tutorial-comprehensions.html)Wed, 06 Jun 2018 06:41:36 +0200https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?comment=42523#post-id-42523Comment by slelievre for <p>To get the documentation on the function you mention, you do:</p>
<pre><code>sage: graphs.planar_graphs?
</code></pre>
<p>which gives:</p>
<pre><code>[...]
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.
[...]
</code></pre>
<p>You may also read the documentation of <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_generators.html#sage.graphs.graph_generators.GraphGenerators.planar_graphs">planar_graphs</a> function online.</p>
<p>The output is not a graph, neither a list. It is an <em>iterator</em> of graphs.</p>
https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?comment=42524#post-id-42524Note 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')Wed, 06 Jun 2018 06:49:36 +0200https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?comment=42524#post-id-42524Comment by standardtrickyness for <p>To get the documentation on the function you mention, you do:</p>
<pre><code>sage: graphs.planar_graphs?
</code></pre>
<p>which gives:</p>
<pre><code>[...]
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.
[...]
</code></pre>
<p>You may also read the documentation of <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_generators.html#sage.graphs.graph_generators.GraphGenerators.planar_graphs">planar_graphs</a> function online.</p>
<p>The output is not a graph, neither a list. It is an <em>iterator</em> of graphs.</p>
https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?comment=42744#post-id-42744Thank 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?Tue, 26 Jun 2018 23:10:07 +0200https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?comment=42744#post-id-42744Answer by slelievre for <p>I find the documentation of Sage much lacking what is the output of <code>plantri</code> and <code>graphs.planar_graphs</code>? </p>
<p>I assumed the output would be graphs (could not find documentation on this) and did the following</p>
<pre><code>l = graphs.planar_graphs(4, dual=False)
gen = list(l)
ii = 1
G = gen[ii]
p = G.plot()
p.show()
</code></pre>
https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?answer=42756#post-id-42756The 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:
- [SageMath documentation for `planar_graphs`](https://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_generators.html#sage.graphs.graph_generators.GraphGenerators.planar_graphs)
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.
Wed, 27 Jun 2018 12:37:43 +0200https://ask.sagemath.org/question/42437/output-of-plantri-and-graphsplanar_graphs/?answer=42756#post-id-42756