Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

networkx.drawing.nx_pylab.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
  • G (graph) – A networkx graph

  • pos (dictionary) – A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2.

  • edge_labels (dictionary, optional) – Edge labels in a dictionary keyed by edge two-tuple of text labels (default=None). Only labels for the keys in the dictionary are drawn.

  • label_pos (float, optional) – Position of edge label along edge (0=head, 0.5=center, 1=tail) (default=0.5)

  • font_size (int, optional) – Font size for text labels (default=10)

  • font_color (string, optional) – Font color string (default=’k’ black)

  • font_family (string, optional) – Font family (default=’sans-serif’)

  • font_weight (string, optional) – Font weight (default=’normal’)

  • alpha (float or None, optional) – The text transparency (default=None)

  • bbox (Matplotlib 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)}.

  • horizontalalignment ({‘center’, ‘right’, ‘left’}, optional) – Horizontal alignment (default=’center’)

  • verticalalignment ({‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}, optional) – Vertical alignment (default=’center’)

  • ax (Matplotlib Axes object, optional) – Draw the graph in the specified Matplotlib axes.

  • rotate (bool, optional) – Rotate edge labels to lie parallel to edges (default=True)

  • clip_on (bool, optional) – Turn on clipping of edge labels at axis boundaries (default=True)

Returns

dict of labels keyed on the edges

Return type

dict

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.github.io/documentation/latest/auto_examples/index.html