Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

generate_graph6

generate_graph6(G, nodes=None, header=True)[source]

Generate graph6 format string from a simple undirected graph.

Parameters:
  • G (Graph (undirected)) –
  • nodes (list or iterable) – Nodes are labeled 0...n-1 in the order provided. If None the ordering given by G.nodes() is used.
  • header (bool) – If True add ‘>>graph6<<’ string to head of data
Returns:

s – String in graph6 format

Return type:

string

Raises:

NetworkXError – If the graph is directed or has parallel edges

Examples

>>> G = nx.Graph([(0, 1)])
>>> nx.generate_graph6(G)
'>>graph6<<A_'

Notes

The format does not support edge or node labels, parallel edges or self loops. If self loops are present they are silently ignored.

References

Graph6 specification: http://cs.anu.edu.au/~bdm/data/formats.txt for details.