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.
- More information on the features provided here are available at
matplotlib: http://matplotlib.org/
pygraphviz: http://pygraphviz.github.io/
Matplotlib¶
Draw networks with matplotlib.
Examples¶
>>> G = nx.complete_graph(5)
>>> nx.draw(G)
See Also¶
|
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 |
|
Draw the graph |
|
Draw a planar networkx graph |
|
Draw the graph |
|
Draw the graph |
|
Draw the graph |
|
Draw networkx graph |
Graphviz AGraph (dot)¶
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: http://pygraphviz.github.io/
Graphviz: https://www.graphviz.org
DOT Language: http://www.graphviz.org/doc/info/lang.html
|
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¶
Import and export NetworkX graphs in Graphviz dot format using pydot.
Either this module or nx_agraph can be used to interface with graphviz.
Examples¶
>>> G = nx.complete_graph(5)
>>> PG = nx.nx_pydot.to_pydot(G)
>>> H = nx.nx_pydot.from_pydot(PG)
See Also¶
Graphviz: https://www.graphviz.org
DOT Language: http://www.graphviz.org/doc/info/lang.html
|
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¶
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. |