NetworkX

Previous topic

networkx.spectral_layout

Next topic

networkx.draw_networkx

networkx.draw

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

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:

>>> G=nx.dodecahedral_graph()
>>> nx.draw(G)
>>> nx.draw(G,pos=nx.spring_layout(G))

Also see doc/examples/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

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()