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)[source]#

Draw node labels on the graph G.

Parameters:
Ggraph

A networkx graph

posdictionary

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

labelsdictionary (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_sizeint (default=12)

Font size for text labels

font_colorcolor (default=’k’ black)

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

font_weightstring (default=’normal’)

Font weight

font_familystring (default=’sans-serif’)

Font family

alphafloat or None (default=None)

The text transparency

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

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

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.

clip_onbool (default=True)

Turn on clipping of node labels at axis boundaries

hide_ticksbool, 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

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