# how make the thickness of the edges reflect the weights?

How Can I represent with thickness of the edges the weights of this graph?

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, EdgeWeight -> {1, 3, 5}]


• Is this a duplicate? Also at least related: (6440) – Mr.Wizard Sep 21 '17 at 22:48

Since you can't refer to a PropertyValue of the graph you are currently constructing, you could have an auxiliary graph that holds the properties, and another graph that draws based on those properties.

For example you could make the color and thickness depend on the weight via

g = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, EdgeWeight -> {2, 8, 14}];

shapeFunc = With[{weight = PropertyValue[{g, #2}, EdgeWeight]},
{AbsoluteThickness[weight], Hue[weight/14.], Line@#1}] &;
Graph[g, EdgeStyle -> Blue, EdgeShapeFunction -> shapeFunc]


The arguments given to the EdgeShapeFunction are 1) the vertex coordinates for the endpoints of the line segment, and 2) the edge itself.

• so with your example color and thickness reflect in same time weights? – Garuda Ikëtum Sep 21 '17 at 21:11
• and with a network of 500 edges for example how can I have a good thick and good representation? – Garuda Ikëtum Sep 21 '17 at 21:14

EdgeStyle can plot the edges with different thicknesses

spec = {1 <-> 2, 2 <-> 3, 3 <-> 1};
thickness = {0.01, 0.02, 0.03};
Graph[spec, EdgeStyle -> Thread[spec -> (Thickness[#] & /@ thickness)]]


Here the thickness of the lines is 1/10 of the original edgeweights, otherwise they are very thick. You can also specify the color the same way:

spec = {1 <-> 2, 2 <-> 3, 3 <-> 1};
thickness = {0.01, 0.02, 0.03};
color = {0., 0.5, 0.6};
Thread@{(Hue[#] & /@ color), (Thickness[#] & /@ thickness)}]]


• Ok @bill s maybe can it be normalize thickness wiith max value of edgeweights? – Garuda Ikëtum Sep 21 '17 at 20:53
• Sure, you can set the values in any desired manner. – bill s Sep 22 '17 at 3:00

With the IGraph/M package, it is very easy to do styling like this. You will find several similar examples in the documentation under Utilities → Property Handling Functions.

IGEdgeMap[
AbsoluteThickness[1.5 #] &,
EdgeStyle -> IGEdgeProp[EdgeWeight],
g
]


What does IGEdgeMap do? It Maps the function AbsoluteThickness[1.5 #] & over the list returned by IGEdgeProp[EdgeWeight][g], and assigned the result to the EdgeStyle edge property of g.

IGEdgeProp[EdgeWeight] is a property extractor. It is a function that, when applied to the graph g, will return the list of EdgeWeights. You can extract any other edge property this way.