Slightly annoying indeed: the show
method for a permutation
- computes a graph corresponding to that permutation
- displays it
- but does not return it
Instead it returns nothing, which in Python amounts to returning None
.
That method should be decomposed into a method that provides
the graph and a method that shows it.
Here is a workaround until such a method is provided.
One can check what the show
method does by inspecting the source code:
sage: p = Permutation([3, 1, 2])
sage: p.show??
This helps us figure out how to produce the graph.
sage: p = Permutation([3, 1, 2])
sage: g = DiGraph([(i+1, p[i]) for i in range(len(p))], loops=True)
sage: g
Looped digraph on 3 vertices
Now we can get the LaTeX TikZ code for it:
sage: latex(g)
\begin{tikzpicture}
\definecolor{cv0}{rgb}{0.0,0.0,0.0}
\definecolor{cfv0}{rgb}{1.0,1.0,1.0}
\definecolor{clv0}{rgb}{0.0,0.0,0.0}
\definecolor{cv1}{rgb}{0.0,0.0,0.0}
\definecolor{cfv1}{rgb}{1.0,1.0,1.0}
\definecolor{clv1}{rgb}{0.0,0.0,0.0}
\definecolor{cv2}{rgb}{0.0,0.0,0.0}
\definecolor{cfv2}{rgb}{1.0,1.0,1.0}
\definecolor{clv2}{rgb}{0.0,0.0,0.0}
\definecolor{cv0v2}{rgb}{0.0,0.0,0.0}
\definecolor{cv1v0}{rgb}{0.0,0.0,0.0}
\definecolor{cv2v1}{rgb}{0.0,0.0,0.0}
%
\Vertex[style={minimum size=1.0cm,draw=cv0,fill=cfv0,text=clv0,shape=circle},LabelOut=false,L=\hbox{$1$},x=1.6204cm,y=5.0cm]{v0}
\Vertex[style={minimum size=1.0cm,draw=cv1,fill=cfv1,text=clv1,shape=circle},LabelOut=false,L=\hbox{$2$},x=0.0cm,y=0.0cm]{v1}
\Vertex[style={minimum size=1.0cm,draw=cv2,fill=cfv2,text=clv2,shape=circle},LabelOut=false,L=\hbox{$3$},x=5.0cm,y=1.1015cm]{v2}
%
\Edge[lw=0.1cm,style={post, bend right,color=cv0v2,},](v0)(v2)
\Edge[lw=0.1cm,style={post, bend right,color=cv1v0,},](v1)(v0)
\Edge[lw=0.1cm,style={post, bend right,color=cv2v1,},](v2)(v1)
%
\end{tikzpicture}
This might print a couple of warnings about required LaTeX packages.
The urls for them are outdated, see instead
Updating those links in the warnings and in the LaTeX tutorial is tracked at