Skip to content
Kevin Murphy edited this page Jan 3, 2014 · 1 revision

Using the Edge Colors Property

I've had a couple questions on how to specify the color of edges. Here is an example:

load smallExample 
nodeColors = {'g','b','r','c'}; % if too few specified, it will cycle through
edgeColors = {'Tom', 'Bill', 'r'
              'Bill' 'all' , 'g'};

graphViz4Matlab('-adjMat',adj,'-nodeLabels',names,'-layout',Treelayout,'-nodeColors',nodeColors,'-edgeColors', edgeColors);

The smallExample data set is part of the download. This is just a modification of graphViz4MatlabDemo1. The nodes are named Tom, Bill, ..., etc.

  • Each row of the edgeColors cell arrays defines a coloring rule. The first entry is the name of the 'from' node, the second is the name of the 'to' node and the third is a color. The color can be a string, as in 'r', or an rgb 1x3 array, i.e. {{{0.8, 0}}}.

  • The keyword 'all' is short hand for all 'from nodes' or all 'to nodes' depending on where it is used.

  • When calling graphViz4Matlab, pass in this edgeColors cell array prefixed by its name '-edgeColors' as above.

  • You can specify as few or as many coloring rules as you like; the arrows not mentioned are left black.

  • If you do not give the nodes your own labels, they are assigned the labels '1', '2', '3', ..., etc. These strings, (not doubles) can then be used to specify the edge colors.