networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
draw_networkx_edges(G, pos, edgelist=None, width=1.0, edge_color='k', style='solid', alpha=None, arrowstyle=None, arrowsize=10, edge_cmap=None, edge_vmin=None, edge_vmax=None, ax=None, arrows=None, label=None, node_size=300, nodelist=None, node_shape='o', connectionstyle='arc3', min_source_margin=0, min_target_margin=0)

This draws only the edges of the graph G.

Notes

For directed graphs, arrows are drawn at the head end. Arrows can be turned off with keyword arrows=False or by passing an arrowstyle without an arrow on the end.

Be sure to include :None:None:`node_size` as a keyword argument; arrows are drawn considering the size of nodes.

Self-loops are always drawn with FancyArrowPatch regardless of the value of :None:None:`arrows` or whether G is directed. When arrows=False or arrows=None and G is undirected, the FancyArrowPatches corresponding to the self-loops are not explicitly returned. They should instead be accessed via the Axes.patches attribute (see examples).

Parameters

G : graph

A networkx graph

pos : dictionary

A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2.

edgelist : collection of edge tuples (default=G.edges())

Draw only specified edges

width : float or array of floats (default=1.0)

Line width of edges

edge_color : color or array of colors (default='k')

Edge color. Can be a single color or a sequence of colors with the same length as edgelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the edge_cmap and edge_vmin,edge_vmax parameters.

style : string or array of strings (default='solid')

Edge line style e.g.: '-', '--', '-.', ':' or words like 'solid' or 'dashed'. Can be a single style or a sequence of styles with the same length as the edge list. If less styles than edges are given the styles will cycle. If more styles than edges are given the styles will be used sequentially and not be exhausted. Also, :None:None:`(offset, onoffseq)` tuples can be used as style instead of a strings. (See matplotlib.patches.FancyArrowPatch : :None:None:`linestyle`)

alpha : float or None (default=None)

The edge transparency

edge_cmap : Matplotlib colormap, optional

Colormap for mapping intensities of edges

edge_vmin,edge_vmax : floats, optional

Minimum and maximum for edge colormap scaling

ax : Matplotlib Axes object, optional

Draw the graph in the specified Matplotlib axes.

arrows : bool or None, optional (default=None)

If :None:None:`None`, directed graphs draw arrowheads with FancyArrowPatch , while undirected graphs draw edges via LineCollection for speed. If :None:None:`True`, draw arrowheads with FancyArrowPatches (bendable and stylish). If :None:None:`False`, draw edges using LineCollection (linear and fast).

Note: Arrowheads will be the same color as edges.

arrowstyle : str (default='-\|>' for directed graphs)

For directed graphs and :None:None:`arrows==True` defaults to '-\|>', For undirected graphs default to '-'.

See matplotlib.patches.ArrowStyle for more options.

arrowsize : int (default=10)

For directed graphs, choose the size of the arrow head's length and width. See matplotlib.patches.FancyArrowPatch for attribute :None:None:`mutation_scale` for more info.

connectionstyle : string (default="arc3")

Pass the connectionstyle parameter to create curved arc of rounding radius rad. For example, connectionstyle='arc3,rad=0.2'. See matplotlib.patches.ConnectionStyle and matplotlib.patches.FancyArrowPatch for more info.

node_size : scalar or array (default=300)

Size of nodes. Though the nodes are not drawn with this function, the node size is used in determining edge positioning.

nodelist : list, optional (default=G.nodes())

This provides the node order for the :None:None:`node_size` array (if it is an array).

node_shape : string (default='o')

The marker used for nodes, used in determining edge positioning. Specification is as a matplotlib.markers marker, e.g. one of 'so^>v<dph8'.

label : None or string

Label for legend

min_source_margin : int (default=0)

The minimum margin (gap) at the begining of the edge at the source.

min_target_margin : int (default=0)

The minimum margin (gap) at the end of the edge at the target.

Returns

matplotlib.colections.LineCollection or a list of matplotlib.patches.FancyArrowPatch

If arrows=True , a list of FancyArrowPatches is returned. If arrows=False , a LineCollection is returned. If arrows=None (the default), then a LineCollection is returned if G is undirected, otherwise returns a list of FancyArrowPatches.

Draw the edges of the graph G.

See Also

draw
draw_networkx
draw_networkx_edge_labels
draw_networkx_labels
draw_networkx_nodes

Examples

>>> G = nx.dodecahedral_graph()
... edges = nx.draw_networkx_edges(G, pos=nx.spring_layout(G))
>>> G = nx.DiGraph()
... G.add_edges_from([(1, 2), (1, 3), (2, 3)])
... arcs = nx.draw_networkx_edges(G, pos=nx.spring_layout(G))
... alphas = [0.3, 0.4, 0.5]
... for i, arc in enumerate(arcs): # change alpha values of arcs
...  arc.set_alpha(alphas[i])

The FancyArrowPatches corresponding to self-loops are not always returned, but can always be accessed via the patches attribute of the :None:None:`matplotlib.Axes` object.

>>> import matplotlib.pyplot as plt
... fig, ax = plt.subplots()
... G = nx.Graph([(0, 1), (0, 0)]) # Self-loop at node 0
... edge_collection = nx.draw_networkx_edges(G, pos=nx.circular_layout(G), ax=ax)
... self_loop_fap = ax.patches[0]

Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.drawing.nx_pylab.draw_networkx networkx.drawing.nx_pylab.draw networkx.drawing.nx_pylab.draw_networkx_labels networkx.drawing.nx_pylab.draw_networkx_edge_labels networkx.drawing.nx_pylab.draw_networkx_edges networkx.drawing.nx_pylab.draw_networkx_nodes

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/drawing/nx_pylab.py#497
type: <class 'function'>
Commit: