Logo Search packages:      
Sourcecode: python-networkx version File versions  Download package

def networkx::drawing::nx_pylab::draw (   G,
  pos = None,
  with_labels = True,
  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:

>>> 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_*

: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')
  - `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()

Definition at line 45 of file nx_pylab.py.

00045                                                :
    """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_*

    :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')
      - `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()

    """
    from matplotlib.pylab import gca, hold, draw_if_interactive 

    if pos is None:
        pos=networkx.drawing.spring_layout(G) # default to spring layout

    ax=gca()
    # allow callers to override the hold state by passing hold=True|False
    b = ax.ishold()
    h = kwds.get('hold', None)
    if h is not None:
        hold(h)
    try:
        # turn of axes ticks and labels
        ax.set_xticks([])
        ax.set_yticks([])
        draw_networkx(G, pos, ax=ax, with_labels=with_labels, **kwds)
        draw_if_interactive()

    except:
        hold(b)
        raise
    hold(b)

def draw_networkx(G, pos, with_labels=True, ax=None, **kwds):


Generated by  Doxygen 1.6.0   Back to index