easygraph.readwrite.graphviz module#

easygraph.readwrite.graphviz.from_agraph(A, create_using=None)[source]#

Returns a EasyGraph Graph or DiGraph from a PyGraphviz graph.

Parameters:
  • A (PyGraphviz AGraph) – A graph created with PyGraphviz

  • create_using (EasyGraph graph constructor, optional (default=None)) – Graph type to create. If graph instance, then cleared before populated. If None, then the appropriate Graph type is inferred from A.

Examples

>>> K5 = eg.complete_graph(5)
>>> A = eg.to_agraph(K5)
>>> G = eg.from_agraph(A)

Notes

The Graph G will have a dictionary G.graph_attr containing the default graphviz attributes for graphs, nodes and edges.

Default node attributes will be in the dictionary G.node_attr which is keyed by node.

Edge attributes will be returned as edge data in G. With edge_attr=False the edge data will be the Graphviz edge weight attribute or the value 1 if no edge weight attribute is found.

easygraph.readwrite.graphviz.read_dot(path)[source]#

Returns a EasyGraph graph from a dot file on path.

Parameters:

path (file or string) – File name or file handle to read.

easygraph.readwrite.graphviz.to_agraph(N)[source]#

Returns a pygraphviz graph from a EasyGraph graph N.

Parameters:

N (EasyGraph graph) – A graph created with EasyGraph

Examples

>>> K5 = eg.complete_graph(5)
>>> A = eg.to_agraph(K5)

Notes

If N has an dict N.graph_attr an attempt will be made first to copy properties attached to the graph (see from_agraph) and then updated with the calling arguments if any.

easygraph.readwrite.graphviz.write_dot(G, path)[source]#

Write EasyGraph graph G to Graphviz dot format on path.

Parameters:
  • G (graph) – A easygraph graph

  • path (filename) – Filename or file handle to write