MATLAB Answers

0

coloring node and edge of a graph

Asked by Deepa Maheshvare on 24 Dec 2018
Latest activity Answered by madhan ravi
on 24 Dec 2018
I have a graph with values assigned to nodes and edges,
t = 1:4;
h = 2:5;
g = graph(t,h);
plot(g)
g.Edges.value = [10; 20; 20; 100];
g.Nodes.value = [0.3; 0.564; 12; 1; 0.005];
I would like to know whether there is an option of coloring the nodes and edges based on the values.

  0 Comments

Sign in to comment.

Tags

Products

2 Answers

Answer by Cris LaPierre on 24 Dec 2018
 Accepted Answer

The highlight function is one way to do this. Check out the examples on this page.

  1 Comment

You could try this page as well. Here's a quick mock up
t = 1:4;
h = 2:5;
g = graph(t,h);
p = plot(g);
g.Edges.value = [10; 20; 20; 100];
g.Nodes.value = [0.3; 0.564; 12; 1; 0.005];
g.Nodes.NodeColors = g.Nodes.value;
g.Edges.EdgeColors = g.Edges.value;
p.NodeCData = g.Nodes.NodeColors;
p.EdgeCData = g.Edges.EdgeColors;
colorbar

Sign in to comment.


Answer by madhan ravi
on 24 Dec 2018

Easy way create a handle to the graph and just use dot indexing and assign the color for instance red , green .. blabla

  0 Comments

Sign in to comment.