easygraph.readwrite.gexf module#
- easygraph.readwrite.gexf.generate_gexf(G, encoding='utf-8', prettyprint=True, version='1.2draft')[source]#
Generate lines of GEXF format representation of G.
“GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics” [1].
- Parameters:
G (graph) –
graph (A EasyGraph) –
encoding (string (optional, default: 'utf-8')) –
data. (Encoding for text) –
prettyprint (bool (optional, default: True)) –
XML. (If True use line breaks and indenting in output) –
version (string (default: 1.2draft)) –
http (Version of GEFX File Format (see) –
values (Supported) –
Examples
>>> G = eg.path_graph(4) >>> linefeed = chr(10) # linefeed=
>>> s = linefeed.join(eg.generate_gexf(G)) >>> for line in eg.generate_gexf(G): ... print(line)
Notes
This implementation does not support mixed graphs (directed and undirected edges together).
The node id attribute is set to be the string of the node label. If you want to specify an id use set it as node data, e.g. node[‘a’][‘id’]=1 to set the id of node ‘a’ to 1.
References
[1]GEXF File Format, https://gephi.org/gexf/format/
- easygraph.readwrite.gexf.read_gexf(path, node_type=None, relabel=False, version='1.2draft')[source]#
Read graph in GEXF format from path.
“GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics” [1].
- Parameters:
path (file or string) – File or file name to read. File names ending in .gz or .bz2 will be decompressed.
node_type (Python type (default: None)) – Convert node ids to this type if not None.
relabel (bool (default: False)) – If True relabel the nodes to use the GEXF node “label” attribute instead of the node “id” attribute as the EasyGraph node label.
version (string (default: 1.2draft)) –
http (Version of GEFX File Format (see) – Supported values: “1.1draft”, “1.2draft”
- Returns:
graph – If no parallel edges are found a Graph or DiGraph is returned. Otherwise a MultiGraph or MultiDiGraph is returned.
- Return type:
EasyGraph graph
Notes
This implementation does not support mixed graphs (directed and undirected edges together).
References
[1]GEXF File Format, http://gexf.net/
- easygraph.readwrite.gexf.relabel_gexf_graph(G)[source]#
Relabel graph using “label” node keyword for node label.
- Parameters:
G (graph) – A EasyGraph graph read from GEXF data
- Returns:
H – A EasyGraph graph with relabeled nodes
- Return type:
graph
- Raises:
EasyGraphError – If node labels are missing or not unique while relabel=True.
Notes
This function relabels the nodes in a EasyGraph graph with the “label” attribute. It also handles relabeling the specific GEXF node attributes “parents”, and “pid”.
- easygraph.readwrite.gexf.write_gexf(G, path, encoding='utf-8', prettyprint=True, version='1.2draft')[source]#
Write G in GEXF format to path.
“GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics” [1]_.
Node attributes are checked according to the version of the GEXF schemas used for parameters which are not user defined, e.g. visualization ‘viz’ [2]_. See example for usage.
- Parameters:
G (graph) – An EasyGraph graph
path (file or string) – File or file name to write. File names ending in .gz or .bz2 will be compressed.
encoding (string (optional, default: 'utf-8')) – Encoding for text data.
prettyprint (bool (optional, default: True)) – If True use line breaks and indenting in output XML.
version (string (optional, default: '1.2draft')) – The version of GEXF to be used for nodes attributes checking
Examples
>>> G = eg.path_graph(4) >>> eg.write_gexf(G, "test.gexf")