1

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

no-one
  • 1,243
  • 9
  • 14

1 Answers1

5

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).

ubpdqn
  • 60,617
  • 3
  • 59
  • 148