Skip to main content
`Ctrl`+`K`

# draw_networkx_labels

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, hide_ticks=True)

  Draw node labels on the graph G.

  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.

    labels dictionary (default={n: n for n in G})

      Node labels in a dictionary of text labels keyed by node. 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 or dictionary of nodes to ints (default=12)

      Font size for text labels.

    font_color color or dictionary of nodes to colors (default=’k’ black)

      Font color string. Color can be string or rgb (or rgba) tuple of floats from 0-1.

    font_weight string or dictionary of nodes to strings (default=’normal’)

      Font weight.

    font_family string or dictionary of nodes to strings (default=’sans-serif’)

      Font family.

    alpha float or None or dictionary of nodes to floats (default=None)

      The text transparency.

    bbox Matplotlib bbox, (default is Matplotlib’s ax.text default)

      Specify text box properties (e.g. shape, color etc.) for node labels.

    horizontalalignment string or array of strings (default=’center’)

      Horizontal alignment {‘center’, ‘right’, ‘left’}. If an array is specified it must be the same length as `nodelist`.

    verticalalignment string (default=’center’)

      Vertical alignment {‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}. If an array is specified it must be the same length as `nodelist`.

    ax Matplotlib Axes object, optional

      Draw the graph in the specified Matplotlib axes.

    clip_on bool (default=True)

      Turn on clipping of node labels at axis boundaries

    hide_ticks bool, optional

      Hide ticks of axes. When `True` (the default), ticks and ticklabels are removed from the axes. To set ticks and tick labels to the pyplot default, use `hide_ticks=False`.

  Returns:
    dict

      `dict` of labels keyed on the nodes

  See also

  `draw`
  `draw_networkx`
  `draw_networkx_nodes`
  `draw_networkx_edges`
  `draw_networkx_edge_labels`

  Examples

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

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