Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For some reason the option DirectedEdges->True, albeit working internally with grid graph, does not appear in the visualisation for 1D and 2D graphs. It also changes the drawing scheme for 3D grids.

1D Grid-Graphs


g1 = GridGraph[{2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True]


enter image description here

which shows no directed edges, even though the incidence matrix is modified correctly:

\begin{equation} \text{IncidenceMatrix[g1]} = \left( \begin{array}{c} -1 \\ 1 \end{array} \right) \end{equation}

Conversely, issuing the command

GridGraph[{1,2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True]


enter image description here

ie, with the directed edges correctly drawn.

2D Grid-Graphs

For 2D graphs, small dimensions print as a directed edge whereas higher dimensions do not. For instance

g = GridGraph[{2, 2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True]


enter image description here

For dimensions {4,2} the graph is:

enter image description here

where some very tiny arrows can in fact be observed. Conversely, for dimensions {2,4} it produces

enter image description here

It thence seems like a problem in adjusting the size of the arrows. But this seems unrelated to the 1D graph since there, no arrow can be seen in any dimension (unless drawn horizontally, in which case a 2D Grid-Graph is actually being called).

3D Grid-Graphs

Apparently, the arrows are drawn correctly for dimensions 3 and larger. However, the drawing scheme is affected, which is not the case in 2D graphs. For instance

 GridGraph[{4, 2, 2}, VertexLabels -> "Name", ImagePadding -> 20]


enter image description here

whereas adding DirectedEdges->True yields

enter image description here

In summary: odd stuff. Any thoughts? Thank you in advance for the attention.

share|improve this question
It seems a problem with the arrows scaling. Try GridGraph[{2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True, EdgeShapeFunction -> GraphElementData["FilledArrow", "ArrowSize" -> 2]] ` – Dr. belisarius Aug 23 '12 at 2:01

There is something wrong with the behavior of EdgeShapeFunction in GridGraph.

AbsoluteOptions[g, EdgeShapeFunction] returns $Failed for all of the examples you give.

Take a look at the this blow-up of g1. There is indeed a tiny arrowhead present.

g1 = GridGraph[{2}, VertexLabels -> "Name", ImageSize -> 300, ImagePadding -> 20, DirectedEdges -> True] 

g1 pic

Verde's suggestion to use GraphElementData["FilledArrow", "ArrowSize" -> 2] handles the issue of arrowhead size. However it introduces a new problem (see magnified pic of Verde's proposed solution). The tip of the arrowhead is now incorrectly positioned at the center of the vertex.

arrow 2

I suggest you call attention of WRI to this as a possible bug.

share|improve this answer
David: I wasn't suggesting to use that! The idea was showing that the arrow is there ... – Dr. belisarius Aug 23 '12 at 3:41
And ... It isn't AbsoluteOptions but PropertyValue what you need to get the option for EdgeShapeFunction – Dr. belisarius Aug 23 '12 at 3:45
Verde: Sorry if I was unable to understand the intent of your comment. Btw, why does AbsoluteOptions return $Failed? – DavidC Aug 23 '12 at 10:45
David, I think WRI is changing the way to access internal structures, but it is only partially done. AbsoluteOptions, PropertyValue, CurrentValue ... I think future versions will converge these – Dr. belisarius Aug 23 '12 at 11:43
@DavidCarraher Thanks for the answer. I'll report it as a possible bug. I am not sure this is related, but GridGraph draws the graph differently from other graphs. – Gabriel Landi Aug 23 '12 at 11:52

As Verde said, it seems an arrow scaling problem:

origgraph = GridGraph[{2},
   VertexLabels -> "Name", DirectedEdges -> True,
   ImagePadding -> 20];

 {arrowstyle = Arrowheads[2]},
 ToBoxes[origgraph] /.
   {Arrowheads[_], ArrowBox[pts_]} :>
    {arrowstyle, ArrowBox[pts]} //

Mathematica graphics

About the overlay problem about GraphElementData["FilledArrow", "ArrowSize" -> 2] described in David's answer, it seems like because when option EdgeShapeFunction -> GraphElementData["FilledArrow", "ArrowSize" -> 2] is specified, explicit coordinates are (incorrectly?) used in ArrowBox instead of DynamicLocation. It can be worked around as following:

origgraph = GridGraph[{2},
   VertexLabels -> "Name", DirectedEdges -> True,
   ImagePadding -> 20, ImageSize -> 100];

arrowgraph = GridGraph[{2},
   VertexLabels -> "Name",
   DirectedEdges -> True,
   EdgeShapeFunction ->
    GraphElementData["FilledArrow", "ArrowSize" -> 2],
   ImagePadding -> 20, ImageSize -> 100];

finalgraph = With[
   {arrowstyle =
     Cases[arrowgraph // ToBoxes,
       Arrowheads[_], \[Infinity]][[1]]},
   ToBoxes[origgraph] /.
     {Arrowheads[_], ArrowBox[pts_]} :>
      {arrowstyle, ArrowBox[pts]} //

Row[{origgraph, arrowgraph, finalgraph}]

Mathematica graphics

share|improve this answer

Your Answer


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.