Message Boards Message Boards

Edge styling in graphs

Posted 10 years ago

Hi Wolfram community,

I guess i have a rather simple problem, but I really have problems to solve it. I have (directed) Graph with about 60 vertices and 3000 edges. To make the graph a little more "handsome" I would like to have edges with a little space between the head of the edges and the vertices and with tiny arrowheads (at the end of an edge) . I found something to fix the spacing problem on the documentation center, but I can't find a direct way to size the arrowheads down using EdgeStyle or EdgeStyleFunction. Subsequent an example picture of my network.

Smal examplel version of my network

POSTED BY: Peanut Butter
6 Replies

Use EdgeShapeFunction. Built in shapes:

RandomGraph[{50, 500},
 DirectedEdges -> True,
 EdgeStyle -> Directive[Opacity[.3], Black],
 GraphLayout -> Automatic,
 VertexLabels -> Placed["Name", Center],
 VertexSize -> .3,
 EdgeShapeFunction -> GraphElementData[{"HalfFilledArrow", "ArrowSize" -> .02}],
 ImageSize -> 800]

enter image description here

Custom shapes:

ef[pts_List, e_] := Block[
  {size = .02,
   offset = .9},
  {Arrowheads[{{size, offset}}], Arrow[pts]}]

RandomGraph[{50, 500},
 DirectedEdges -> True,
 EdgeStyle -> Directive[Opacity[.3], Black],
 GraphLayout -> Automatic,
 VertexLabels -> Placed["Name", Center],
 VertexSize -> .3,
 EdgeShapeFunction -> ef,
 ImageSize -> 800]

enter image description here

POSTED BY: Vitaliy Kaurov

In

http://reference.wolfram.com/language/tutorial/GraphDrawing.html

there is this example of varying the size of the arrow heads for directed graphs. Could this be what you are looking for?

Table[
 GraphPlot[{1 -> 6, 2 -> 6, 3 -> 6, 4 -> 6, 5 -> 6}, ImageSize -> 100,
   DirectedEdges -> {True, "ArrowheadsSize" -> asize}, 
  VertexLabeling -> True], {asize, {0.05, 0.1, 0.15}}]
POSTED BY: David Reiss

It would be very useful if you edit your post add code - in the body of post or as an attachment.

POSTED BY: Sam Carrettie
Posted 10 years ago

@ David, thanks for the hint. I allready saw that, but i would rather work with an Graph object (if that's possible).

@ Sam, yes that would make sense, my code looks like this:

example = RandomGraph[{50, 500}, DirectedEdges -> True,
  EdgeStyle -> Gray,
  GraphLayout -> Automatic,
  VertexLabels -> Table[i -> Placed[i, Center], {i, 50}]]
POSTED BY: Peanut Butter
Posted 10 years ago

Comes a little late, but thank you that was exactly what i was looking for! :)

POSTED BY: Peanut Butter
Posted 10 years ago

Or you can specify Arrowheads in EdgeStyle options:

RandomGraph[{50, 500}, DirectedEdges -> True, 
 EdgeStyle -> Directive[Arrowheads[.01], Opacity[.3], Black], 
 GraphLayout -> Automatic, VertexLabels -> Placed["Name", Center], 
 VertexSize -> .3, ImageSize -> 800]
POSTED BY: Jaebum Jung
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract