Skip to main content
added 14 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

if {a,b} and {b,a} are edges, I would like one line between them that has two arrowheads

ClearAll[modiFy]
modiFymodiFy[as_ =: Graph[DeleteDuplicates[EdgeList{-.05, @.05}] #:= Graph[DeleteDuplicates[EdgeList@#, Sort @ # == Sort @ #2 &], 
 EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList@#, Reverse @ e] :> 
   Arrowheads[{-.05, .05}]Arrowheads[as]}, VertexCoordinates -> GraphEmbedding[#], Options @ #]&

Examples:

g1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

modiFymodiFy[] @ g1

enter image description here

modiFy[{-.08, .05}] @ g1

enter image description here

g2 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}, ImageSize -> 400,
  EdgeLabels -> Placed["Name", 1/3], ImagePadding -> 20,  VertexLabels -> "Name"]

enter image description here

modiFymodiFy[] @ g2

enter image description here

if {a,b} and {b,a} are edges, I would like one line between them that has two arrowheads

ClearAll[modiFy]
modiFy = Graph[DeleteDuplicates[EdgeList @ #, Sort @ # == Sort @ #2 &], 
 EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList@#, Reverse @ e] :> 
   Arrowheads[{-.05, .05}]}, VertexCoordinates -> GraphEmbedding[#], Options @ #]&

Examples:

g1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

modiFy @ g1

enter image description here

g2 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}, ImageSize -> 400,
  EdgeLabels -> Placed["Name", 1/3], ImagePadding -> 20,  VertexLabels -> "Name"]

enter image description here

modiFy @ g2

enter image description here

if {a,b} and {b,a} are edges, I would like one line between them that has two arrowheads

ClearAll[modiFy]
modiFy[as_ : {-.05, .05}] := Graph[DeleteDuplicates[EdgeList@#, Sort @ # == Sort @ #2 &], 
 EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList@#, Reverse @ e] :> 
   Arrowheads[as]}, VertexCoordinates -> GraphEmbedding[#], Options @ #]&

Examples:

g1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

modiFy[] @ g1

enter image description here

modiFy[{-.08, .05}] @ g1

enter image description here

g2 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}, ImageSize -> 400,
  EdgeLabels -> Placed["Name", 1/3], ImagePadding -> 20,  VertexLabels -> "Name"]

enter image description here

modiFy[] @ g2

enter image description here

added 368 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

if {a,b} and {b,a} are edges, I would like one line between them that has two arrowheads

ClearAll[modiFy]
modiFy = Graph[DeleteDuplicates[EdgeList @ #, Sort @ # == Sort @ #2 &], 
 EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList@#, Reverse @ e] :> 
   Arrowheads[{-.05, .05}]}, VertexCoordinates -> GraphEmbedding[#], Options @ #]&

You can use the option EdgeStyle after removing duplicate (up to direction) edges:Examples:

gg1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

Graph[DeleteDuplicates[EdgeList[g],modiFy Sort@#@ ==g1

enter image description here

g2 Sort@#2= &]Graph[{1 -> 2, 
 2 EdgeStyle-> 1, 3 -> {e1, :3 DirectedEdge[a_-> 2, b_]4 /;-> a1, =!=4 b-> &&2, MemberQ[EdgeList[g]4 -> 4}, Reverse@e]ImageSize :-> 400,
   EdgeLabels Arrowheads[{-.05> Placed["Name", .05}]}1/3], VertexCoordinatesImagePadding -> GraphEmbedding[g]]20,  VertexLabels -> "Name"]

enter image description hereenter image description here

modiFy @ g2

enter image description here

You can use the option EdgeStyle after removing duplicate (up to direction) edges:

g = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

Graph[DeleteDuplicates[EdgeList[g], Sort@# == Sort@#2 &], 
  EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList[g], Reverse@e] :> 
    Arrowheads[{-.05, .05}]}, VertexCoordinates -> GraphEmbedding[g]]

enter image description here

if {a,b} and {b,a} are edges, I would like one line between them that has two arrowheads

ClearAll[modiFy]
modiFy = Graph[DeleteDuplicates[EdgeList @ #, Sort @ # == Sort @ #2 &], 
 EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList@#, Reverse @ e] :> 
   Arrowheads[{-.05, .05}]}, VertexCoordinates -> GraphEmbedding[#], Options @ #]&

Examples:

g1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

modiFy @ g1

enter image description here

g2 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}, ImageSize -> 400,
  EdgeLabels -> Placed["Name", 1/3], ImagePadding -> 20,  VertexLabels -> "Name"]

enter image description here

modiFy @ g2

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You can use the option EdgeStyle after removing duplicate (up to direction) edges:

g = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]

enter image description here

Graph[DeleteDuplicates[EdgeList[g], Sort@# == Sort@#2 &], 
 EdgeStyle -> {e : DirectedEdge[a_, b_] /; a =!= b && MemberQ[EdgeList[g], Reverse@e] :> 
    Arrowheads[{-.05, .05}]}, VertexCoordinates -> GraphEmbedding[g]]

enter image description here