networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesBackRef
write_gml(G, path, stringizer=None)

Notes

Graph attributes named 'directed', 'multigraph', 'node' or 'edge', node attributes named 'id' or 'label', edge attributes named 'source' or 'target' (or 'key' if G is a multigraph) are ignored because these attribute names are used to encode the graph structure.

GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. Without specifying a :None:None:`stringizer`/destringizer , the code is capable of writing :None:None:`int`/:None:None:`float`/:None:None:`str`/:None:None:`dict`/:None:None:`list` data as required by the GML specification. For writing other data types, and for reading data other than :None:None:`str` you need to explicitly supply a :None:None:`stringizer`/destringizer .

Note that while we allow non-standard GML to be read from a file, we make sure to write GML format. In particular, underscores are not allowed in attribute names. For additional documentation on the GML file format, please see the GML url.

See the module docstring networkx.readwrite.gml for more details.

Parameters

G : NetworkX graph

The graph to be converted to GML.

path : filename or filehandle

The filename or filehandle to write. Files whose names end with .gz or .bz2 will be compressed.

stringizer : callable, optional

A :None:None:`stringizer` which converts non-int/non-float/non-dict values into strings. If it cannot convert a value into a string, it should raise a :None:None:`ValueError` to indicate that. Default value: None.

Raises

NetworkXError

If :None:None:`stringizer` cannot convert a value into a string, or the value to convert is not a string while :None:None:`stringizer` is None.

Write a graph G in GML format to the file or file handle :None:None:`path`.

See Also

generate_gml
literal_stringizer
read_gml

Examples

>>> G = nx.path_graph(4)
... nx.write_gml(G, "test.gml")

Filenames ending in .gz or .bz2 will be compressed.

>>> nx.write_gml(G, "test.gml.gz")
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.readwrite.gml.read_gml networkx.readwrite.gml.write_gml networkx.readwrite.gml.parse_gml

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/readwrite/gml.py#794
type: <class 'function'>
Commit: