Drawing¶
NetworkX provides basic functionality for visualizing graphs, but its main goal is to enable graph analysis rather than perform graph visualization. In the future, graph visualization functionality may be removed from NetworkX or only available as an add-on package.
Proper graph visualization is hard, and we highly recommend that people
visualize their graphs with tools dedicated to that task. Notable examples of
dedicated and fully-featured graph visualization tools are
Cytoscape,
Gephi,
Graphviz and, for
LaTeX typesetting,
PGF/TikZ.
To use these and other such tools, you should export your NetworkX graph into
a format that can be read by those tools. For example, Cytoscape can read the
GraphML format, and so, networkx.write_graphml(G, path)
might be an appropriate
choice.
Matplotlib¶
|
Draw the graph G with Matplotlib. |
|
Draw the graph G using Matplotlib. |
|
Draw the nodes of the graph G. |
|
Draw the edges of the graph G. |
|
Draw node labels on the graph G. |
|
Draw edge labels. |
|
Draw the graph G with a circular layout. |
|
Draw the graph G with a Kamada-Kawai force-directed layout. |
|
Draw a planar networkx graph with planar layout. |
|
Draw the graph G with a random layout. |
|
Draw the graph G with a spectral 2D layout. |
|
Draw the graph G with a spring layout. |
|
Draw networkx graph with shell layout. |
Graphviz AGraph (dot)¶
Graphviz AGraph¶
Interface to pygraphviz AGraph class.
Examples
>>> G = nx.complete_graph(5)
>>> A = nx.nx_agraph.to_agraph(G)
>>> H = nx.nx_agraph.from_agraph(A)
See also
Pygraphviz
|
Returns a NetworkX Graph or DiGraph from a PyGraphviz graph. |
|
Returns a pygraphviz graph from a NetworkX graph N. |
|
Write NetworkX graph G to Graphviz dot format on path. |
|
Returns a NetworkX graph from a dot file on path. |
|
Create node positions for G using Graphviz. |
|
Create node positions for G using Graphviz. |
Graphviz with pydot¶
Pydot¶
Import and export NetworkX graphs in Graphviz dot format using pydot.
Either this module or nx_agraph can be used to interface with graphviz.
|
Returns a NetworkX graph from a Pydot graph. |
|
Returns a pydot graph from a NetworkX graph N. |
|
Write NetworkX graph G to Graphviz dot format on path. |
|
Returns a NetworkX |
|
Create node positions using Pydot and Graphviz. |
|
Create node positions using |
Graph Layout¶
Layout¶
Node positioning algorithms for graph drawing.
For random_layout()
the possible resulting shape
is a square of side [0, scale] (default: [0, 1])
Changing center
shifts the layout by that amount.
For the other layout routines, the extent is [center - scale, center + scale] (default: [-1, 1]).
Warning: Most layout routines have only been tested in 2-dimensions.
|
Position nodes in two straight lines. |
|
Position nodes on a circle. |
|
Position nodes using Kamada-Kawai path-length cost-function. |
|
Position nodes without edge intersections. |
|
Position nodes uniformly at random in the unit square. |
|
Returns scaled position array to (-scale, scale) in all axes. |
|
Return a dictionary of scaled positions keyed by node |
|
Position nodes in concentric circles. |
|
Position nodes using Fruchterman-Reingold force-directed algorithm. |
|
Position nodes using the eigenvectors of the graph Laplacian. |
|
Position nodes in a spiral layout. |
|
Position nodes in layers of straight lines. |