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

def networkx::drawing::nx_pylab::draw_networkx_edges (   G,
  pos,
  edgelist = None,
  width = 1.0,
  edge_color = 'k',
  style = 'solid',
  alpha = 1.0,
  ax = None,
  kwds 
)

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. 

See draw_networkx for the list of other optional parameters.

Definition at line 217 of file nx_pylab.py.

                               :
    """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. 
    
    See draw_networkx for the list of other optional parameters.

    """
    from matplotlib.pylab import gca, hold, draw_if_interactive 
    if ax is None:
        ax=gca()

    if edgelist is None:
        edgelist=G.edges()

    if not edgelist: # no edges!
        return None

    # set edge positions
    head=[]
    tail=[]
    for e in edgelist:
        # edge e can be a 2-tuple (Graph) or a 3-tuple (Xgraph)
        u=e[0]
        v=e[1]
        head.append(pos[u])
        tail.append(pos[v])
    edge_pos=asarray(zip(head,tail))

    if not cb.iterable(width):
        lw = (width,)
    else:
        lw = width

    # edge colors specified with floats won't work here
    # since LineCollection doesn't use ScalarMappable.
    # You can use an array of RGBA or text labels
    if not cb.is_string_like(edge_color) \
           and cb.iterable(edge_color) \
           and len(edge_color)==len(edge_pos):
        edge_colors = None
    else:
        edge_colors = ( colorConverter.to_rgba(edge_color, alpha), )

    edge_collection = LineCollection(edge_pos,
                                colors       = edge_colors,
                                linewidths   = lw,
                                antialiaseds = (1,),
                                linestyle    = style,     
                                transOffset = ax.transData,             
                                )
    edge_collection.set_alpha(alpha)
    arrow_collection=None

    if G.is_directed():

        # a directed graph hack
        # draw thick line segments at head end of edge
        # waiting for someone else to implement arrows that will work 
        arrow_colors = ( colorConverter.to_rgba('k', alpha), )
        a_pos=[]
        p=1.0-0.25 # make head segment 25 percent of edge length
        for src,dst in edge_pos:
            x1,y1=src
            x2,y2=dst
            dx=x2-x1 # x offset
            dy=y2-y1 # y offset
            d=sqrt(float(dx**2+dy**2)) # length of edge
            if d==0: # source and target at same position
                continue
            if dx==0: # vertical edge
                xa=x2
                ya=dy*p+y1
            if dy==0: # horizontal edge
                ya=y2
                xa=dx*p+x1
            else:
                theta=arctan2(dy,dx)
                xa=p*d*cos(theta)+x1
                ya=p*d*sin(theta)+y1
                
            a_pos.append(((xa,ya),(x2,y2)))

        arrow_collection = LineCollection(a_pos,
                                colors       = arrow_colors,
                                linewidths   = lw*4,
                                antialiaseds = (1,),
                                transOffset = ax.transData,             
                                )
        
    # update view        
    xx= [x for (x,y) in head+tail]        
    yy= [y for (x,y) in head+tail]        
    minx = amin(xx)
    maxx = amax(xx)
    miny = amin(yy)
    maxy = amax(yy)
    w = maxx-minx
    h = maxy-miny
    padx, pady = 0.05*w, 0.05*h
    corners = (minx-padx, miny-pady), (maxx+padx, maxy+pady)
    ax.update_datalim( corners)
    ax.autoscale_view()

    edge_collection.set_zorder(1) # edges go behind nodes            
    ax.add_collection(edge_collection)
    if arrow_collection:
        arrow_collection.set_zorder(1) # edges go behind nodes            
        ax.add_collection(arrow_collection)


    return edge_collection


def draw_networkx_labels(G, pos,


Generated by  Doxygen 1.6.0   Back to index