Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

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

Matplotlib

Draw networks with matplotlib.

draw(G[, pos, ax])

Draw the graph G with Matplotlib.

draw_networkx(G[, pos, arrows, with_labels])

Draw the graph G using Matplotlib.

draw_networkx_nodes(G, pos[, nodelist, …])

Draw the nodes of the graph G.

draw_networkx_edges(G, pos[, edgelist, …])

Draw the edges of the graph G.

draw_networkx_labels(G, pos[, labels, …])

Draw node labels on the graph G.

draw_networkx_edge_labels(G, pos[, …])

Draw edge labels.

draw_circular(G, **kwargs)

Draw the graph G with a circular layout.

draw_kamada_kawai(G, **kwargs)

Draw the graph G with a Kamada-Kawai force-directed layout.

draw_planar(G, **kwargs)

Draw a planar networkx graph with planar layout.

draw_random(G, **kwargs)

Draw the graph G with a random layout.

draw_spectral(G, **kwargs)

Draw the graph G with a spectral 2D layout.

draw_spring(G, **kwargs)

Draw the graph G with a spring layout.

draw_shell(G, **kwargs)

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

http://pygraphviz.github.io/

from_agraph(A[, create_using])

Returns a NetworkX Graph or DiGraph from a PyGraphviz graph.

to_agraph(N)

Returns a pygraphviz graph from a NetworkX graph N.

write_dot(G, path)

Write NetworkX graph G to Graphviz dot format on path.

read_dot(path)

Returns a NetworkX graph from a dot file on path.

graphviz_layout(G[, prog, root, args])

Create node positions for G using Graphviz.

pygraphviz_layout(G[, prog, root, args])

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.

from_pydot(P)

Returns a NetworkX graph from a Pydot graph.

to_pydot(N)

Returns a pydot graph from a NetworkX graph N.

write_dot(G, path)

Write NetworkX graph G to Graphviz dot format on path.

read_dot(path)

Returns a NetworkX MultiGraph or MultiDiGraph from the dot file with the passed path.

graphviz_layout(G[, prog, root])

Create node positions using Pydot and Graphviz.

pydot_layout(G[, prog, root])

Create node positions using pydot and Graphviz.

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.

bipartite_layout(G, nodes[, align, scale, …])

Position nodes in two straight lines.

circular_layout(G[, scale, center, dim])

Position nodes on a circle.

kamada_kawai_layout(G[, dist, pos, weight, …])

Position nodes using Kamada-Kawai path-length cost-function.

planar_layout(G[, scale, center, dim])

Position nodes without edge intersections.

random_layout(G[, center, dim, seed])

Position nodes uniformly at random in the unit square.

rescale_layout(pos[, scale])

Returns scaled position array to (-scale, scale) in all axes.

shell_layout(G[, nlist, scale, center, dim])

Position nodes in concentric circles.

spring_layout(G[, k, pos, fixed, …])

Position nodes using Fruchterman-Reingold force-directed algorithm.

spectral_layout(G[, weight, scale, center, dim])

Position nodes using the eigenvectors of the graph Laplacian.

spiral_layout(G[, scale, center, dim, …])

Position nodes in a spiral layout.