highlight

Colors chosen nodes or edges of a graph plot.

Category: Mathematics > Graph and Network Algorithms

Syntax

highlight(p, nodeIDs)

Highlights the nodes in the plot p.

highlight(p, s, t)

Highlights the edges between each pair s(k), t(k).

highlight(___, Name, Value)

Sets the look of the highlight: 'NodeColor', 'EdgeColor', 'LineWidth', 'MarkerSize'.

Description

highlight changes how the plot looks without changing the graph. A typical use is to draw the output of a path or search on top of the whole network: pass the nodes of a shortestpath result, then the same list shifted by one as s and t to color the edges between consecutive nodes.

The figure appears below the code in the app.

Input arguments

p
GraphPlot object returned by plot(G) for a graph or digraph.
nodeIDs
Node indices or names.
s, t
End nodes of the edges to highlight.
'NodeColor', 'EdgeColor'
Color as a letter such as 'r' or an RGB triplet. The default highlight color is red.

Example

Highlight a shortest path

G = graph([1 1 2 3 4 4], [2 3 4 4 5 6]);
p = plot(G);
path = shortestpath(G, 1, 6);
highlight(p, path, 'NodeColor', 'r', 'MarkerSize', 8)
highlight(p, path(1:end-1), path(2:end), 'EdgeColor', 'r', 'LineWidth', 3)

In the app, the path from node 1 to node 6 is drawn in red.

Notes

Passing a graph object (highlight(p, H)) is not supported; give node indices or end-node pairs.

See also

plot labelnode labeledge layout shortestpath