networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturns
read_graphml(path, node_type=<class 'str'>, edge_key_type=<class 'int'>, force_multigraph=False)

Notes

Default node and edge attributes are not propagated to each node and edge. They can be obtained from :None:None:`G.graph` and applied to node and edge attributes if desired using something like this:

>>> default_color = G.graph["node_default"]["color"]  # doctest: +SKIP
>>> for node, data in G.nodes(data=True):  # doctest: +SKIP
...     if "color" not in data:
...         data["color"] = default_color
>>> default_color = G.graph["edge_default"]["color"]  # doctest: +SKIP
>>> for u, v, data in G.edges(data=True):  # doctest: +SKIP
...     if "color" not in data:
...         data["color"] = default_color

This implementation does not support mixed graphs (directed and unidirected edges together), hypergraphs, nested graphs, or ports.

For multigraphs the GraphML edge "id" will be used as the edge key. If not specified then they "key" attribute will be used. If there is no "key" attribute a default NetworkX multigraph edge key will be provided.

Files with the yEd "yfiles" extension can be read. The type of the node's shape is preserved in the :None:None:`shape_type` node attribute.

yEd compressed files ("file.graphmlz" extension) can be read by renaming the file to "file.graphml.gz".

Parameters

path : file or string

File or filename to write. Filenames ending in .gz or .bz2 will be compressed.

node_type: Python type (default: str) :

Convert node ids to this type

edge_key_type: Python type (default: int) :

Convert graphml edge ids to this type. Multigraphs use id as edge key. Non-multigraphs add to edge attribute dict with name "id".

force_multigraph : bool (default: False)

If True, return a multigraph with edge keys. If False (the default) return a multigraph when multiedges are in the graph.

Returns

graph: NetworkX graph

If parallel edges are present or :None:None:`force_multigraph=True` then a MultiGraph or MultiDiGraph is returned. Otherwise a Graph/DiGraph. The returned graph is directed if the file indicates it should be.

Read graph in GraphML format from path.

Examples

See :

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/graphml.py#236
type: <class 'function'>
Commit: