Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

highlight

Highlight nodes and edges in plotted graph

Syntax

highlight(H,nodeIDs)
highlight(H,G)
highlight(H,s,t)
highlight(___,Name,Value)

Description

example

highlight(H,nodeIDs) highlights the nodes specified by nodeIDs by increasing the sizes of their markers.

example

highlight(H,G) highlights the nodes and edges of graph G by increasing their node marker size and edge line width, respectively. G must have the same nodes and a subset of the edges of the underlying graph of H. Isolated nodes with degree 0 are not highlighted.

highlight(H,s,t) highlights the edges specified by the source and target node pairs in s and t by increasing their edge line widths.

example

highlight(___,Name,Value) uses additional options specified by one or more Name-Value pair arguments using any of the input argument combinations in previous syntaxes. For example, highlight(H,nodes,'NodeColor','g') highlights a subset of nodes by changing their color to green, instead of increasing their marker size.

Examples

collapse all

Create and plot a graph. Return a handle to the GraphPlot object, h.

s = 1;
t = 2:6;
G = graph(s,t);
h = plot(G,'Layout','force')
h = 
  GraphPlot with properties:

     NodeColor: [0 0.4470 0.7410]
    MarkerSize: 4
        Marker: 'o'
     EdgeColor: [0 0.4470 0.7410]
     LineWidth: 0.5000
     LineStyle: '-'
     NodeLabel: {'1'  '2'  '3'  '4'  '5'  '6'}
     EdgeLabel: {}
         XData: [1.8894e-04 1.7637 -1.2603 0.8165 -1.5953 0.2752]
         YData: [-1.3730e-04 -0.2841 1.2666 1.5949 -0.8091 -1.7681]
         ZData: [0 0 0 0 0 0]

  Show all properties

Highlight nodes 1 and 3 by increasing their marker size.

highlight(h,[1 3])

Highlight nodes 1 and 3 by changing their color.

highlight(h,[1 3],'NodeColor','g')

Create and plot a graph. Return a handle to the GraphPlot object, h.

s = [1 1 1 1 1 1 2 3 4 5 6 7 7 7 7 8 9 10 11 8 6];
t = [2 3 4 5 6 7 3 4 5 6 2 8 9 10 11 10 10 11 8 1 11];
G = graph(s,t);
h = plot(G)
h = 
  GraphPlot with properties:

     NodeColor: [0 0.4470 0.7410]
    MarkerSize: 4
        Marker: 'o'
     EdgeColor: [0 0.4470 0.7410]
     LineWidth: 0.5000
     LineStyle: '-'
     NodeLabel: {'1'  '2'  '3'  '4'  '5'  '6'  '7'  '8'  '9'  '10'  '11'}
     EdgeLabel: {}
         XData: [1x11 double]
         YData: [1x11 double]
         ZData: [0 0 0 0 0 0 0 0 0 0 0]

  Show all properties

Calculate the minimum spanning tree of the graph. Highlight the minimum spanning tree subgraph in the plot by increasing the line width and changing the color of the edges in the tree.

[T,p] = minspantree(G);
highlight(h,T,'EdgeColor','r','LineWidth',1.5)

Create and plot a graph. Return a handle to the GraphPlot object, h.

n = 10;
A = delsq(numgrid('L',n+2));
G = graph(A,'OmitSelfLoops'); 
G.Edges.Weight = ones(numedges(G),1);
h = plot(G);

Highlight the shortest path between nodes 74 and 21 by changing the color of the nodes and edges along the path to green.

path = shortestpath(G,74,21);
highlight(h,path,'NodeColor','g','EdgeColor','g')

Create a graph representing a square grid with a side of 8 nodes. Plot the graph and return a handle to the GraphPlot object, p.

n = 8;
A = delsq(numgrid('S',n+2));
G = graph(A,'OmitSelfLoops');
p = plot(G);

Find the neighbors of node 36.

n36 = neighbors(G,36)
n36 = 

    28
    35
    37
    44

Use highlight to change the color of node 36 to green, and the color of its neighbors and their connecting edges to red.

highlight(p,36,'NodeColor',[0 0.75 0])
highlight(p,n36,'NodeColor','red')
highlight(p,36,n36,'EdgeColor','red')

Create and plot a directed graph. Return a handle to the GraphPlot object, h.

G = digraph(bucky);
h = plot(G);

Compute the maximum flow between nodes 1 and 56. Specify two outputs to maxflow to return a directed graph of the nonzero flows, GF.

[mf,GF] = maxflow(G,1,56)
mf = 3
GF = 
  digraph with properties:

    Edges: [28x2 table]
    Nodes: [60x0 table]

Use highlight to change the color of the edges that contain nonzero flow values. Also change the color of source node 1 and target node 56 to green.

highlight(h,GF,'EdgeColor',[0.9 0.3 0.1],'NodeColor',[0.9 0.3 0.1])
highlight(h,[1 56],'NodeColor','g')

Input Arguments

collapse all

Input graph plot, specified as a GraphPlot object. Use the graph or digraph functions to create a graph, and then use plot with an output argument to return a GraphPlot object.

Example: H = plot(G)

Nodes to highlight, specified as a vector of node indices, a logical vector, a node name, or a cell array of character vectors containing node names.

Data Types: single | double | logical | char | cell

Graph to highlight, specified as a graph or digraph object. G must have the same nodes and a subset of the edges of the underlying graph of H. Isolated nodes with degree 0 are not highlighted.

Edges to highlight, specified as separate arguments that indicate the end nodes of the edges as scalar node indices, vectors of node indices, character vector node names, or cell arrays of character vectors containing node names.

Example: highlight(H,[1 2],[3 3]) highlights the graph edges (1,3) and (2,3).

Example: highlight(H,'a','b') highlights the edge ('a','b').

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: highlight(H,nodes,'NodeColor','y')

collapse all

Edge color, specified as the comma-separated pair consisting of 'EdgeColor' and an RGB triplet or color name.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

    OptionDescriptionEquivalent RGB Triplet
    'red' or 'r'Red[1 0 0]
    'green' or 'g'Green[0 1 0]
    'blue' or 'b'Blue[0 0 1]
    'yellow' or 'y'Yellow[1 1 0]
    'magenta' or 'm'Magenta[1 0 1]
    'cyan' or 'c'Cyan[0 1 1]
    'white' or 'w'White[1 1 1]
    'black' or 'k'Black[0 0 0]

Example: plot(G,'EdgeColor','r') creates a graph plot with red edges.

Line style, specified as the comma-separated pair consisting of 'LineStyle' and one of the line styles listed in this table.

Character(s)Line StyleResulting Line
'-'Solid line

'--'Dashed line

':'Dotted line

'-.'Dash-dotted line

'none'No lineNo line

Edge line width, specified as the comma-separated pair consisting of 'LineWidth' and a positive value in point units.

Example: 0.75

Node marker symbol, specified as the comma-separated pair consisting of 'Marker' and one of the character vectors listed in this table. The default is to use circular markers for the graph nodes.

ValueDescription
'o'Circle
'+'Plus sign
'*'Asterisk
'.'Point
'x'Cross
'square' or 's'Square
'diamond' or 'd'Diamond
'^'Upward-pointing triangle
'v'Downward-pointing triangle
'>'Right-pointing triangle
'<'Left-pointing triangle
'pentagram' or 'p'Five-pointed star (pentagram)
'hexagram' or 'h'Six-pointed star (hexagram)
'none'No markers

Example: '+'

Example: 'diamond'

Node marker size, specified as the comma-separated pair consisting of 'MarkerSize' and a positive value in point units. The default marker size is 4 for graphs with 100 or fewer nodes, and 2 for graphs with more than 100 nodes.

Example: 10

Node color, specified as the comma-separated pair consisting of 'NodeColor' and an RGB triplet or color name.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

    OptionDescriptionEquivalent RGB Triplet
    'red' or 'r'Red[1 0 0]
    'green' or 'g'Green[0 1 0]
    'blue' or 'b'Blue[0 0 1]
    'yellow' or 'y'Yellow[1 1 0]
    'magenta' or 'm'Magenta[1 0 1]
    'cyan' or 'c'Cyan[0 1 1]
    'white' or 'w'White[1 1 1]
    'black' or 'k'Black[0 0 0]

Example: plot(G,'NodeColor','k') creates a graph plot with black nodes.

Introduced in R2015b

Was this topic helpful?