0
$\begingroup$

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 = 
Thread[el -> (Directive[CapForm["Round"], 
    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 = 
Thread[el -> (Directive[CapForm["Round"], 
    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...

$\endgroup$
1
$\begingroup$

You can use Graph3D.

el = {1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 4};
edgestylea = 
  Thread[el -> (Directive[CapForm["Round"], 
        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.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ I want to plot my graph with the legend too. Can you help me? $\endgroup$ – Gae P Apr 5 '17 at 14:17
  • $\begingroup$ you could use Legended: Legended[graph, SwatchLegend[{Red, Green, Blue}, {"red", "green", "blue"}]] $\endgroup$ – halmir Apr 5 '17 at 20:41
  • $\begingroup$ I would like to use a barlegend with min=Min[q] and max=Max[q]. How can I do it? $\endgroup$ – Gae P Apr 6 '17 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.