draw_networkx_edge_labels#

draw_networkx_edge_labels(G, pos, edge_labels=None, label_pos=0.5, font_size=10, font_color='k', font_family='sans-serif', font_weight='normal', alpha=None, bbox=None, horizontalalignment='center', verticalalignment='center', ax=None, rotate=True, clip_on=True)[source]#

Draw edge labels.

Parameters:
Ggraph

A networkx graph

posdictionary

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

edge_labelsdictionary (default=None)

Edge labels in a dictionary of labels keyed by edge two-tuple. Only labels for the keys in the dictionary are drawn.

label_posfloat (default=0.5)

Position of edge label along edge (0=head, 0.5=center, 1=tail)

font_sizeint (default=10)

Font size for text labels

font_colorstring (default=’k’ black)

Font color string

font_weightstring (default=’normal’)

Font weight

font_familystring (default=’sans-serif’)

Font family

alphafloat or None (default=None)

The text transparency

bboxMatplotlib bbox, optional

Specify text box properties (e.g. shape, color etc.) for edge labels. Default is {boxstyle=’round’, ec=(1.0, 1.0, 1.0), fc=(1.0, 1.0, 1.0)}.

horizontalalignmentstring (default=’center’)

Horizontal alignment {‘center’, ‘right’, ‘left’}

verticalalignmentstring (default=’center’)

Vertical alignment {‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}

axMatplotlib Axes object, optional

Draw the graph in the specified Matplotlib axes.

rotatebool (default=True)

Rotate edge labels to lie parallel to edges

clip_onbool (default=True)

Turn on clipping of edge labels at axis boundaries

Returns:
dict

dict of labels keyed by edge

Examples

>>> G = nx.dodecahedral_graph()
>>> edge_labels = nx.draw_networkx_edge_labels(G, pos=nx.spring_layout(G))

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