NetworkX

Previous topic

networkx.drawing.nx_pylab.draw

Next topic

networkx.drawing.nx_pylab.draw_networkx_nodes

networkx.drawing.nx_pylab.draw_networkx

networkx.drawing.nx_pylab.draw_networkx(G, pos=None, with_labels=True, **kwds)

Draw the graph G using Matplotlib.

Draw the graph with Matplotlib with options for node positions, labeling, titles, and many other drawing features. See draw() for simple drawing without labels or axes.

Parameters :

G : graph

A networkx graph

pos : dictionary, optional

A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. See networkx.layout for functions that compute node positions.

ax : Matplotlib Axes object, optional

Draw the graph in the specified Matplotlib axes.

with_labels: bool, optional :

Set to True (default) to draw labels on the nodes.

nodelist: list, optional :

Draw only specified nodes (default G.nodes())

edgelist: list :

Draw only specified edges(default=G.edges())

node_size: scalar or array :

Size of nodes (default=300). If an array is specified it must be the same length as nodelist.

node_color: color string, or array of floats :

Node color. Can be a single color format string (default=’r’), or a sequence of colors with the same length as nodelist. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details.

node_shape: string :

The shape of the node. Specification is as matplotlib.scatter marker, one of ‘so^>v<dph8’ (default=’o’).

alpha: float :

The node transparency (default=1.0)

cmap: Matplotlib colormap :

Colormap for mapping intensities of nodes (default=None)

vmin,vmax: floats :

Minimum and maximum for node colormap scaling (default=None)

width`: float :

Line width of edges (default =1.0)

edge_color: color string, or array of floats :

Edge color. Can be a single color format string (default=’r’), or a sequence of colors with the same length as edgelist. If numeric values are specified they will be mapped to colors using the edge_cmap and edge_vmin,edge_vmax parameters.

edge_ cmap: Matplotlib colormap :

Colormap for mapping intensities of edges (default=None)

edge_vmin,edge_vmax: floats :

Minimum and maximum for edge colormap scaling (default=None)

style: string :

Edge line style (default=’solid’) (solid|dashed|dotted,dashdot)

labels: dictionary :

Node labels in a dictionary keyed by node of text labels (default=None)

font_size: int :

Font size for text labels (default=12)

font_color: string :

Font color string (default=’k’ black)

font_weight: string :

Font weight (default=’normal’)

font_family: string :

Font family (default=’sans-serif’)

Notes

Any keywords not listed above are passed through to draw_networkx_nodes(), draw_networkx_edges(), and draw_networkx_labels(). For finer control of drawing you can call those functions directly.

Examples

>>> G=nx.dodecahedral_graph()
>>> nx.draw(G)
>>> nx.draw(G,pos=nx.spring_layout(G)) # use spring layout
>>> import pylab
>>> limits=pylab.axis('off') # turn of axis 

Also see the NetworkX drawing examples at http://networkx.lanl.gov/gallery.html