networkx.readwrite.graphml.read_graphml¶
-
read_graphml
(path, node_type=<type 'str'>, edge_key_type=<type 'int'>)[source]¶ Read graph in GraphML format from path.
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 as key of multi-edges
Returns: graph – If no parallel edges are found a Graph or DiGraph is returned. Otherwise a MultiGraph or MultiDiGraph is returned.
Return type: NetworkX graph
Notes
Default node and edge attributes are not propagated to each node and edge. They can be obtained from
G.graph
and applied to node and edge attributes if desired using something like this:>>> default_color = G.graph['node_default']['color'] >>> for node, data in G.nodes(data=True): ... if 'color' not in data: ... data['color']=default_color >>> default_color = G.graph['edge_default']['color'] >>> for u, v, data in G.edges(data=True): ... 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 will can be read but the graphics information is discarded.
yEd compressed files (“file.graphmlz” extension) can be read by renaming the file to “file.graphml.gz”.