# GraphPlot3D different colours of edges

How can I plot edges with different colours in a GraphPlot3D? Porperties of edges are collected in a vector, I want to plot each edges in a range of colours consistent to these properties.

    q = {1, -1, 1};
Graph1 = Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3,
3 \[DirectedEdge] 4}, EdgeWeight -> q];
ew = PropertyValue[Graph1, EdgeWeight];
el = EdgeList[Graph1];
edgestylea =
Thickness[Rescale[#, Through@{Min, Max}@ew, {0.02, .06}]],
ColorData[1, #]] & /@ ew)];
GraphPlot3D[Graph1, VertexLabeling -> True,
EdgeRenderingFunction -> ({EdgeStyle -> edgestylea ,
Cylinder[#1, .5]} &),
VertexRenderingFunction -> ({Yellow, Sphere[#, 1]} &),
VertexCoordinateRules -> {{0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10,
10, 0}} , AxesOrigin -> {0, 0, 0}, Axes -> True,
PlotLabel ->
Style[Framed["Grafo"], 20, White, Background -> Lighter[Blue]]]


My code...

q = {100, 40, -10};
Graph1 = Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3,
3 \[DirectedEdge] 4}, EdgeWeight -> q];
ew = PropertyValue[Graph1, EdgeWeight];
el = EdgeList[Graph1];
edgestylea =
Thickness[Rescale[#, Through@{Min, Max}@ew, {0.02, .06}]],
ColorData["Rainbow"][#]] & /@ ew)];
Legended[Graph3D[el, EdgeStyle -> edgestylea, EdgeWeight -> q,
EdgeShapeFunction -> (Cylinder[#1, .5] &),
VertexShapeFunction -> ({Yellow, Sphere[#, 1]} &),
VertexCoordinates -> {{0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10,
0}}, AxesOrigin -> {0, 0, 0}, Axes -> True,
PlotLabel ->
Style[Framed["Grafo"], 20, White, Background -> Lighter[Blue]]],
BarLegend[{"Rainbow", {Min[q], Max[q]}}]]


It doesn't work...

You can use Graph3D.

el = {1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 4};
edgestylea =
Thickness[Rescale[#, Through@{Min, Max}@ew, {0.02, .06}]],
ColorData["TemperatureMap"][#]] & /@ ew)];

Graph3D[el, EdgeStyle -> edgestylea, EdgeWeight -> q,
EdgeShapeFunction -> (Cylinder[#1, .5] &),
VertexShapeFunction -> ({Yellow, Sphere[#, 1]} &),
VertexCoordinates -> {{0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10,
0}}, AxesOrigin -> {0, 0, 0}, Axes -> True,
PlotLabel ->
Style[Framed["Grafo"], 20, White, Background -> Lighter[Blue]]]


I changed ColorData[1,#] to ColorData["TemperatureMap"][#] due to -1 value.

• I want to plot my graph with the legend too. Can you help me? Commented Apr 5, 2017 at 14:17
• you could use Legended: Legended[graph, SwatchLegend[{Red, Green, Blue}, {"red", "green", "blue"}]] Commented Apr 5, 2017 at 20:41
• I would like to use a barlegend with min=Min[q] and max=Max[q]. How can I do it? Commented Apr 6, 2017 at 16:07