Export

This module provides exports for graphs.

pyrigi.graph._export.export.layout(graph, layout_type='spring')[source]

Generate a placement of the vertices.

This function is a wrapper for the functions spring_layout(), random_layout(), circular_layout() and planar_layout().

Parameters:
  • graph (Graph)

  • layout_type (str) – The supported layouts are circular, planar, random and spring (default).

Return type:

dict[Vertex, Point]

pyrigi.graph._export.export.to_int(graph, vertex_order=None)[source]

Return the integer representation of the graph.

The graph integer representation is the integer whose binary expansion is given by the sequence obtained by concatenation of the rows of the upper triangle of the adjacency matrix, excluding the diagonal.

Parameters:
  • graph (Graph)

  • vertex_order (Sequence[Vertex]) – By listing vertices in the preferred order, the adjacency matrix is computed with the given order. If no vertex order is provided, vertex_list() is used.

Return type:

int

Examples

>>> G = Graph([(0,1), (1,2)])
>>> adjacency_matrix(G)
Matrix([
[0, 1, 0],
[1, 0, 1],
[0, 1, 0]])
>>> to_int(G)
5

Suggested Improvements

Implement taking canonical before computing the integer representation.

pyrigi.graph._export.export.to_tikz(graph, layout_type='spring', placement=None, vertex_style='gvertex', edge_style='edge', label_style='labelsty', figure_opts='', vertex_in_labels=False, vertex_out_labels=False, default_styles=True)[source]

Create a TikZ code for the graph.

For using it in LaTeX you need to use the tikz package.

Parameters:
  • graph (Graph)

  • placement (dict[Vertex, Point]) – If placement is not specified, then it is generated depending on parameter layout.

  • layout_type (str) – The possibilities are spring (default), circular, random or planar, see also layout().

  • vertex_style (str | dict[str, Sequence[Vertex]]) – If a single style is given as a string, then all vertices get this style. If a dictionary from styles to a list of vertices is given, vertices are put in style accordingly. The vertices missing in the dictionary do not get a style.

  • edge_style (str | dict[str, Sequence[Edge]]) – If a single style is given as a string, then all edges get this style. If a dictionary from styles to a list of edges is given, edges are put in style accordingly. The edges missing in the dictionary do not get a style.

  • label_style (str) – The style for labels that are placed next to vertices.

  • figure_opts (str) – Options for the tikzpicture environment.

  • vertex_in_labels (bool) – A bool on whether vertex names should be put as labels on the vertices.

  • vertex_out_labels (bool) – A bool on whether vertex names should be put next to vertices.

  • default_styles (bool) – A bool on whether default style definitions should be put to the options.

Return type:

str

Examples

>>> G = Graph([(0,1), (1,2), (2,3), (0,3)])
>>> print(to_tikz(G))
\begin{tikzpicture}[gvertex/.style={fill=black,draw=white,circle,inner sep=0pt,minimum size=4pt},edge/.style={line width=1.5pt,black!60!white}]
    \node[gvertex] (0) at (-0.98794, -0.61705) {};
    \node[gvertex] (1) at (0.62772, -1.0) {};
    \node[gvertex] (2) at (0.98514, 0.62151) {};
    \node[gvertex] (3) at (-0.62492, 0.99554) {};
    \draw[edge] (0) to (1) (0) to (3) (1) to (2) (2) to (3);
\end{tikzpicture}
>>> print(to_tikz(G, layout_type = "circular"))
\begin{tikzpicture}[gvertex/.style={fill=black,draw=white,circle,inner sep=0pt,minimum size=4pt},edge/.style={line width=1.5pt,black!60!white}]
    \node[gvertex] (0) at (1.0, 0.0) {};
    \node[gvertex] (1) at (-0.0, 1.0) {};
    \node[gvertex] (2) at (-1.0, -0.0) {};
    \node[gvertex] (3) at (0.0, -1.0) {};
    \draw[edge] (0) to (1) (0) to (3) (1) to (2) (2) to (3);
\end{tikzpicture}
>>> print(to_tikz(G, placement = {0:[0, 0], 1:[1, 1], 2:[2, 2], 3:[3, 3]}))
\begin{tikzpicture}[gvertex/.style={fill=black,draw=white,circle,inner sep=0pt,minimum size=4pt},edge/.style={line width=1.5pt,black!60!white}]
    \node[gvertex] (0) at (0, 0) {};
    \node[gvertex] (1) at (1, 1) {};
    \node[gvertex] (2) at (2, 2) {};
    \node[gvertex] (3) at (3, 3) {};
    \draw[edge] (0) to (1) (0) to (3) (1) to (2) (2) to (3);
\end{tikzpicture}
>>> print(to_tikz(G, layout_type = "circular", vertex_out_labels = True))
\begin{tikzpicture}[gvertex/.style={fill=black,draw=white,circle,inner sep=0pt,minimum size=4pt},edge/.style={line width=1.5pt,black!60!white},labelsty/.style={font=\scriptsize,black!70!white}]
    \node[gvertex,label={[labelsty]right:$0$}] (0) at (1.0, 0.0) {};
    \node[gvertex,label={[labelsty]right:$1$}] (1) at (-0.0, 1.0) {};
    \node[gvertex,label={[labelsty]right:$2$}] (2) at (-1.0, -0.0) {};
    \node[gvertex,label={[labelsty]right:$3$}] (3) at (0.0, -1.0) {};
    \draw[edge] (0) to (1) (0) to (3) (1) to (2) (2) to (3);
\end{tikzpicture}
>>> print(to_tikz(G, layout_type = "circular", vertex_in_labels = True))
\begin{tikzpicture}[gvertex/.style={white,fill=black,draw=black,circle,inner sep=1pt,font=\scriptsize},edge/.style={line width=1.5pt,black!60!white}]
    \node[gvertex] (0) at (1.0, 0.0) {$0$};
    \node[gvertex] (1) at (-0.0, 1.0) {$1$};
    \node[gvertex] (2) at (-1.0, -0.0) {$2$};
    \node[gvertex] (3) at (0.0, -1.0) {$3$};
    \draw[edge] (0) to (1) (0) to (3) (1) to (2) (2) to (3);
\end{tikzpicture}
>>> print(to_tikz(
...     G,
...     layout_type = "circular",
...     vertex_style = "myvertex",
...     edge_style = "myedge")
... )
\begin{tikzpicture}[]
    \node[myvertex] (0) at (1.0, 0.0) {};
    \node[myvertex] (1) at (-0.0, 1.0) {};
    \node[myvertex] (2) at (-1.0, -0.0) {};
    \node[myvertex] (3) at (0.0, -1.0) {};
    \draw[myedge] (0) to (1) (0) to (3) (1) to (2) (2) to (3);
\end{tikzpicture}
>>> print(to_tikz(
...     G,
...     layout_type="circular",
...     edge_style={"red edge": [[1, 2]], "green edge": [[2, 3], [0, 1]]},
...     vertex_style={"red vertex": [0], "blue vertex": [2, 3]})
... )
\begin{tikzpicture}[]
    \node[red vertex] (0) at (1.0, 0.0) {};
    \node[blue vertex] (2) at (-1.0, -0.0) {};
    \node[blue vertex] (3) at (0.0, -1.0) {};
    \node[] (1) at (-0.0, 1.0) {};
    \draw[red edge] (1) to (2);
    \draw[green edge] (2) to (3) (0) to (1);
    \draw[] (0) to (3);
\end{tikzpicture}