Package networkx :: Package drawing :: Module nx_pygraphviz
[hide private]
[frames] | no frames]

Module nx_pygraphviz

source code

Import and export networkx networks to dot format using pygraphviz.

Provides:

and the graph layout methods:

Does not currently handle graphviz subgraphs.

Either this module or nx_pydot can be used to interface with graphviz.

References:



Date: $Date: 2005-06-15 08:55:33 -0600 (Wed, 15 Jun 2005) $

Author: Aric Hagberg (hagberg@lanl.gov)

Functions [hide private]
 
write_dot(G, path)
Write NetworkX graph G to Graphviz dot format on path.
source code
 
read_dot(path)
Return a NetworkX Graph from a dot file on path.
source code
 
to_pygraphviz(N, graph_attr=None, node_attr=None, edge_attr=None)
Creates a pygraphviz graph from an networkx graph N.
source code
 
from_pygraphviz(A, create_using=None, graph_attr=None, node_attr=None, edge_attr=None)
Creates an networkx graph from an pygraphviz graph A.
source code
 
networkx_from_pygraphviz(A, create_using=None, graph_attr=None, node_attr=None, edge_attr=None)
Creates an networkx graph from an pygraphviz graph A.
source code
 
pygraphviz_from_networkx(N, graph_attr=None, node_attr=None, edge_attr=None)
Creates a pygraphviz graph from an networkx graph N.
source code
 
xgraph_from_pygraphviz(A)
Convert from a pygraphviz graph to a NetworkX XGraph.
source code
 
to_pygraphviz_from_xgraph(G)
Convert from a NetworkX XGraph with attributes to a pygraphviz graph.
source code
 
graphviz_layout(G, prog='neato', root=None, args='')
Create layout using graphviz.
source code
 
pygraphviz_layout(G, prog='neato', root=None, args='')
Create layout using pygraphviz and graphviz.
source code
 
_which(name)
searches for executable in path
source code
 
_test_suite() source code
Variables [hide private]
  __credits__ = ''
  __revision__ = '$Revision: 1034 $'
Function Details [hide private]

write_dot(G, path)

source code 

Write NetworkX graph G to Graphviz dot format on path.

Path can be a string or a file handle.

read_dot(path)

source code 

Return a NetworkX Graph from a dot file on path.

Path can be a string or a file handle.

to_pygraphviz(N, graph_attr=None, node_attr=None, edge_attr=None)

source code 

Creates a pygraphviz graph from an networkx graph N.

This simplest use creates a pygraphviz graph with no attributes, just the nodes and edges. Attributes can be added by modifying the resulting pygraphviz graph.

Optional arguments graph_attr, node_attr, edge_attr are used to specify Graphviz graph properties to applied during the conversion. http://www.graphviz.org/doc/info/attrs.html

The graph_attr, node_attr, and edge_attr arguments can be either a dictionary or function as follows:

graph_attr:

dictionary with keys as attribute names and values as attribute values or function that returns a dictionary of attribute names and values The function takes one argument - the graph name:

def graph_attr(G):
    a={'color':'red','label'='my graph'}
    return a
node_attr:

dictionary keyed by node name that has as a value a dictionary of attribute names and values. or function that returns a dictionary of attribute names and values The function takes two arguments - the graph name and node name:

def node_attr(G,n):
    a={'color':'red','shape'='diamond'}
    return a
edge_attr:

dictionary keyed by edge tuple (u,v) that has as a value a dictionary of attribute names and values. or function that returns a dictionary of attribute names and values The function takes two arguments - the graph name and edge tuple e:

def edge_attr(G,e):
    a={'color':'red','shape'='diamond'}
    return a

from_pygraphviz(A, create_using=None, graph_attr=None, node_attr=None, edge_attr=None)

source code 

Creates an networkx graph from an pygraphviz graph A.

This simplest use creates a netwrkx graph and ignores graphviz attributes.

Optional arguments graph_attr, node_attr, edge_attr are used to get graph properties. http://www.graphviz.org/doc/info/attrs.html

The graph_attr, node_attr, and edge_attr arguments can be either a dictionary or function as follows:

graph_attr:

empty dictionary will be filled with keys as attribute names and values as attribute values or A function that takes two arguments - the NetworkX graph and attributes:

def graph_attr(G,a):
    print a # just print attributes
    return
node_attr:

empty dictionary will be filled with keys as nodes with value set to a dictionary of attribute names and values. or A function that takes three arguments - the graph name, node name and attributes:

def node_attr(G,n,a):
    print n,a # print node and attributes
    return a
edge_attr:

empty dictionary will be filled with keys as edge tuples (u,v) with a value set to a dictionary of attribute names and values. or A function that takes three arguments - the graph name, edge tuple, and attributes:

def edge_attr(G,n,e):
    print e,a # print node and attributes
    return a

create_using is an optional networkx graph type. The default is to use a Graph or DiGraph depending on the type of the pygraphviz graph A

networkx_from_pygraphviz(A, create_using=None, graph_attr=None, node_attr=None, edge_attr=None)

source code 

Creates an networkx graph from an pygraphviz graph A.

This simplest use creates a netwrkx graph and ignores graphviz attributes.

Optional arguments graph_attr, node_attr, edge_attr are used to get graph properties. http://www.graphviz.org/doc/info/attrs.html

The graph_attr, node_attr, and edge_attr arguments can be either a dictionary or function as follows:

graph_attr:

empty dictionary will be filled with keys as attribute names and values as attribute values or A function that takes two arguments - the NetworkX graph and attributes:

def graph_attr(G,a):
    print a # just print attributes
    return
node_attr:

empty dictionary will be filled with keys as nodes with value set to a dictionary of attribute names and values. or A function that takes three arguments - the graph name, node name and attributes:

def node_attr(G,n,a):
    print n,a # print node and attributes
    return a
edge_attr:

empty dictionary will be filled with keys as edge tuples (u,v) with a value set to a dictionary of attribute names and values. or A function that takes three arguments - the graph name, edge tuple, and attributes:

def edge_attr(G,n,e):
    print e,a # print node and attributes
    return a

create_using is an optional networkx graph type. The default is to use a Graph or DiGraph depending on the type of the pygraphviz graph A

pygraphviz_from_networkx(N, graph_attr=None, node_attr=None, edge_attr=None)

source code 

Creates a pygraphviz graph from an networkx graph N.

This simplest use creates a pygraphviz graph with no attributes, just the nodes and edges. Attributes can be added by modifying the resulting pygraphviz graph.

Optional arguments graph_attr, node_attr, edge_attr are used to specify Graphviz graph properties to applied during the conversion. http://www.graphviz.org/doc/info/attrs.html

The graph_attr, node_attr, and edge_attr arguments can be either a dictionary or function as follows:

graph_attr:

dictionary with keys as attribute names and values as attribute values or function that returns a dictionary of attribute names and values The function takes one argument - the graph name:

def graph_attr(G):
    a={'color':'red','label'='my graph'}
    return a
node_attr:

dictionary keyed by node name that has as a value a dictionary of attribute names and values. or function that returns a dictionary of attribute names and values The function takes two arguments - the graph name and node name:

def node_attr(G,n):
    a={'color':'red','shape'='diamond'}
    return a
edge_attr:

dictionary keyed by edge tuple (u,v) that has as a value a dictionary of attribute names and values. or function that returns a dictionary of attribute names and values The function takes two arguments - the graph name and edge tuple e:

def edge_attr(G,e):
    a={'color':'red','shape'='diamond'}
    return a

xgraph_from_pygraphviz(A)

source code 

Convert from a pygraphviz graph to a NetworkX XGraph.

A NetworkX XGraph XG is returned with

XG.attr - a dictionary set to the graphviz graph attributes XG.nattr - a dictionary keyed by node with graphviz graph attributes

and the edge data set to a dictionary of graphviz edge attributes.

to_pygraphviz_from_xgraph(G)

source code 
Convert from a NetworkX XGraph with attributes to a pygraphviz graph. See from_pygraphviz_to_xgraph for the special XGraph format.

graphviz_layout(G, prog='neato', root=None, args='')

source code 

Create layout using graphviz. Returns a dictionary of positions keyed by node.

>>> from networkx import *
>>> G=petersen_graph()
>>> pos=graphviz_layout(G)
>>> pos=graphviz_layout(G,prog='dot')

This is a wrapper for pygraphviz_layout.

pygraphviz_layout(G, prog='neato', root=None, args='')

source code 

Create layout using pygraphviz and graphviz. Returns a dictionary of positions keyed by node.

>>> from networkx import *
>>> G=petersen_graph()
>>> pos=pygraphviz_layout(G)
>>> pos=pygraphviz_layout(G,prog='dot')