1
$\begingroup$

I have been trying to understand the following function

l = {{1, 3}, {3, 4}};
GraphPlot[{1 -> 2, 3 -> 4, 1 -> 3, 2 -> 4, 1 -> 2, 3 -> 4}, 
 VertexLabeling -> True, 
 EdgeRenderingFunction -> (If[
     Intersection[l, {#2}] != {}, {Red, Arrow[#1, .1]}, {Blue, 
      Arrow[#1, .1]}] &)]

(Courtesy of the link: Coloring edges in GraphPlot).

I am unable to understand how the slot function is working..i.e., how Intersection[l,{#2}] is working out.

Could someone please explain this

Thanks

$\endgroup$
1

1 Answer 1

5
$\begingroup$

You can get insight into what the arguments for EdgeRenderingFunction are by "looking under the hood",e.g.

GraphPlot[{1 -> 2, 3 -> 4, 1 -> 3, 2 -> 4, 1 -> 2, 3 -> 4}, 
 VertexLabeling -> True, 
 EdgeRenderingFunction -> (If[Intersection[l, {#2}] != {}, 
     Print[{#1, #2, #3}]; {Red, Arrow[#1, .1]}, {Blue, 
      Arrow[#1, .1]}] &)]

You will slot 1 (#1) are the coordinates of the edge ends, #2 is the vertex pair, and the third slot is any label specified for edge (in this case).

So the code aims to color edges {1,3},{3,4} blue (non-empty intersection with l) or red (disjoint with l).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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