Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm graphing a Markov process

mp = DiscreteMarkovProcess[{1, 0, 0}, ({
     {0.6, 0.1, 0.3},
     {0.2, 0.7, 0.1},
     {0.3, 0.3, 0.4}
    })];

and would like to have arrows whose thicknesses corresponds to the transition probabilities, with arrowheads of a different color in the exact center of each edge. But all my attempts end up a mess.

g = Graph[mp];
Scan[(PropertyValue[{g, #}, EdgeLabels] = 
     PropertyValue[{g, #}, "Probability"]) &, EdgeList[g]];
Scan[(PropertyValue[{g, #}, EdgeStyle] =
     Directive[Arrowheads[{{.045, .575}}], GrayLevel[.7], 
      Thickness[PropertyValue[{g, #}, "Probability"]/20]]) &, 
  EdgeList[g]];
g

![enter image description here][1] The thick edges leave gaps between their ends and the nodes of the graph, and I can't figure out how to change the color of the arrow heads so that they stand out against the color of the edges.

How can I change the color of the arrowheads in my figure. How can I avoid the gaps that appear between nodes and the ends of the edges?

share|improve this question
    
Take a look at EdgeShapeFunction. –  wxffles May 7 at 22:47
    
@wxffles: Looks intriguing; but I'm not sure where to go with it. It seems to amount to "build it from scratch". –  raxacoricofallapatorius May 7 at 23:21
add comment

1 Answer 1

up vote 5 down vote accepted

Using an EdgeShapeFunction seems to do what you want. Adapting from the examples in the help:

ef[pts_List, e_] :=
 {Arrowheads[{{0.1, 0.5, Graphics@{Red, Arrowheads[0.5], Arrow[{{0, 0}, {0.5, 0}}]}}}], 
  Arrow[pts]}

g = Graph[mp];
Scan[(PropertyValue[{g, #}, EdgeLabels] = 
    PropertyValue[{g, #}, "Probability"]) &, EdgeList[g]];
Scan[(PropertyValue[{g, #}, EdgeStyle] = 
    Directive[GrayLevel[.7], Thickness[PropertyValue[{g, #}, "Probability"]/20]]) &, 
    EdgeList[g]];
Scan[(PropertyValue[{g, #}, EdgeShapeFunction] = ef) &, EdgeList[g]];
g

red arrows

It's a bit ugly, with mysterious red dots within the arrowheads. But this only reflects how little time I've put into it. With some competence and patience I suspect it could do what you want.

Edit: Something nicer:

ef[pts_List, e_] := {Arrowheads[{{0.02, 0.65, 
    Graphics@{Red, EdgeForm[Gray], Polygon[{{-1.5, -1}, {1.5, 0}, {-1.5, 1}}]}
  }}], Arrow[pts]}

red arrows 2

share|improve this answer
    
Is there a way to keep the arc shapes of the original? –  raxacoricofallapatorius May 8 at 0:47
    
Not easily as far as I can tell. It's just using the points that it gets passed. I'm not sure what the default EdgeShapeFunctions do to it. –  wxffles May 8 at 1:05
    
@wxffles How to access the built-in set of arrow heads is described here. –  Alexey Popkov May 8 at 7:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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