labelnode

Adds labels to the nodes of a graph plot.

Category: Mathematics > Graph and Network Algorithms

Syntax

labelnode(p, nodeIDs, labels)

Labels the listed nodes with labels.

labelnode(p, nodeIDs, 'auto')

Restores the default labels (node names or numbers).

Description

By default a plotted graph labels its nodes with their names, or with their numbers when unnamed. labelnode replaces the label of chosen nodes with any text, for example city names or computed values, without renaming the nodes in the graph itself.

Input arguments

p
GraphPlot object returned by plot(G).
nodeIDs
Node indices or names.
labels
Cell array of text, one per node listed.

Example

Custom node labels

G = graph([1 2 3], [2 3 4]);
p = plot(G);
labelnode(p, 1:4, {'start','a','b','end'})

In the app, the nodes show the new labels.

See also

labeledge highlight plot layout