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


draw_networkx_labels(G, pos, labels=None, font_size=12, font_color='k', font_family='sans-serif', font_weight='normal', alpha=None, bbox=None, horizontalalignment='center', verticalalignment='center', ax=None, clip_on=True)[source]

Draw node labels on the graph G.

  • G (graph) – A networkx graph

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

  • labels (dictionary, optional (default=None), optional) – Node labels in a dictionary keyed by node of text labels Node-keys in labels should appear as keys in pos. If needed use: {n:lab for n,lab in labels.items() if n in pos}

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

  • 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 labels. Default is None, i.e. use the Matplotlib defaults.

  • 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.

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


dict of labels keyed on the nodes

Return type



>>> G = nx.dodecahedral_graph()
>>> labels = nx.draw_networkx_labels(G, pos=nx.spring_layout(G))

Also see the NetworkX drawing examples at