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

Module nx_pylab

source code

Draw networks with matplotlib (pylab).

Provides:

References:



Date: $Date: 2005-06-15 11:29:39 -0600 (Wed, 15 Jun 2005) $

Author: Aric Hagberg (hagberg@lanl.gov)

Functions [hide private]
 
draw(G, pos=None, ax=None, hold=None, **kwds)
Draw the graph G with matplotlib (pylab).
source code
 
draw_networkx(G, pos, with_labels=True, **kwds)
Draw the graph G with given node positions pos
source code
 
draw_networkx_nodes(G, pos, nodelist=None, node_size=300, node_color='r', node_shape='o', alpha=1.0, cmap=None, vmin=None, vmax=None, ax=None, linewidths=None, **kwds)
Draw nodes of graph G
source code
 
draw_networkx_edges(G, pos, edgelist=None, width=1.0, edge_color='k', style='solid', alpha=1.0, edge_cmap=None, edge_vmin=None, edge_vmax=None, ax=None, arrows=True, **kwds)
Draw the edges of the graph G
source code
 
draw_networkx_labels(G, pos, labels=None, font_size=12, font_color='k', font_family='sans-serif', font_weight='normal', alpha=1.0, ax=None, **kwds)
Draw node labels on the graph G
source code
 
draw_circular(G, **kwargs)
Draw the graph G with a circular layout
source code
 
draw_random(G, **kwargs)
Draw the graph G with a random layout.
source code
 
draw_spectral(G, **kwargs)
Draw the graph G with a spectral layout.
source code
 
draw_spring(G, **kwargs)
Draw the graph G with a spring layout
source code
 
draw_shell(G, **kwargs)
Draw networkx graph with shell layout
source code
 
draw_graphviz(G, prog="neato", **kwargs)
Draw networkx graph with graphviz layout
source code
 
draw_nx(G, pos, **kwds)
For backward compatibility; use draw or draw_networkx
source code
 
_test_suite() source code
Variables [hide private]
  __credits__ = """"""
  __revision__ = "$Id"
Function Details [hide private]

draw(G, pos=None, ax=None, hold=None, **kwds)

source code 

Draw the graph G with matplotlib (pylab).

This is a pylab friendly function that will use the current pylab figure axes (e.g. subplot).

pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx.layout for functions that compute node positions.

Usage:

>>> from networkx import *
>>> G=dodecahedral_graph()
>>> draw(G)
>>> pos=graphviz_layout(G)
>>> draw(G,pos)
>>> draw(G,pos=spring_layout(G))

Also see doc/examples/draw_*

for more see pylab.scatter

NB: this has the same name as pylab.draw so beware when using

>>> from networkx import *

since you will overwrite the pylab.draw function.

A good alternative is to use

>>> import pylab as P
>>> import networkx as NX
>>> G=NX.dodecahedral_graph()

and then use

>>> NX.draw(G)  # networkx draw()

and >>> P.draw() # pylab draw()

Parameters:
  • nodelist - list of nodes to be drawn (default=G.nodes())
  • edgelist - list of edges to be drawn (default=G.edges())
  • node_size - scalar or array of the same length as nodelist (default=300)
  • node_color - single color string or numeric/numarray array of floats (default='r')
  • node_shape - node shape (default='o'), or 'so^>v<dph8' see pylab.scatter
  • alpha - transparency (default=1.0)
  • cmap - colormap for mapping intensities (default=None)
  • vmin, vmax - min and max for colormap scaling (default=None)
  • width - line width of edges (default =1.0)
  • edge_color - scalar or array (default='k')
  • edge_cmap - colormap for edge intensities (default=None)
  • edge_vmin, edge_vmax - min and max for colormap edge scaling (default=None)
  • style - edge linestyle (default='solid') (solid|dashed|dotted,dashdot)
  • labels - dictionary keyed by node of text labels (default=None)
  • font_size - size for text labels (default=12)
  • font_color - (default='k')
  • font_weight - (default='normal')
  • font_family - (default='sans-serif')
  • ax - matplotlib axes instance

draw_networkx(G, pos, with_labels=True, **kwds)

source code 

Draw the graph G with given node positions pos

Usage:

>>> from networkx import *
>>> import pylab as P
>>> ax=P.subplot(111)
>>> G=dodecahedral_graph()
>>> pos=spring_layout(G)
>>> draw_networkx(G,pos,ax=ax)

This is same as 'draw' but the node positions must be specified in the variable pos. pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx.layout for functions that compute node positions.

An optional matplotlib axis can be provided through the optional keyword ax.

with_labels contols text labeling of the nodes

Also see:

draw_networkx_nodes() draw_networkx_edges() draw_networkx_labels()

draw_networkx_nodes(G, pos, nodelist=None, node_size=300, node_color='r', node_shape='o', alpha=1.0, cmap=None, vmin=None, vmax=None, ax=None, linewidths=None, **kwds)

source code 

Draw nodes of graph G

This draws only the nodes of the graph G.

pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx.layout for functions that compute node positions.

nodelist is an optional list of nodes in G to be drawn. If provided only the nodes in nodelist will be drawn.

see draw_networkx for the list of other optional parameters.

draw_networkx_edges(G, pos, edgelist=None, width=1.0, edge_color='k', style='solid', alpha=1.0, edge_cmap=None, edge_vmin=None, edge_vmax=None, ax=None, arrows=True, **kwds)

source code 

Draw the edges of the graph G

This draws only the edges of the graph G.

pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx.layout for functions that compute node positions.

edgelist is an optional list of the edges in G to be drawn. If provided, only the edges in edgelist will be drawn.

edgecolor can be a list of matplotlib color letters such as 'k' or 'b' that lists the color of each edge; the list must be ordered in the same way as the edge list. Alternatively, this list can contain numbers and those number are mapped to a color scale using the color map edge_cmap.

For directed graphs, "arrows" (actually just thicker stubs) are drawn at the head end. Arrows can be turned off with keyword arrows=False.

See draw_networkx for the list of other optional parameters.

draw_networkx_labels(G, pos, labels=None, font_size=12, font_color='k', font_family='sans-serif', font_weight='normal', alpha=1.0, ax=None, **kwds)

source code 

Draw node labels on the graph G

pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx.layout for functions that compute node positions.

labels is an optional dictionary keyed by vertex with node labels as the values. If provided only labels for the keys in the dictionary are drawn.

See draw_networkx for the list of other optional parameters.