14
$\begingroup$

This is a nice graph:

g = CycleGraph[4];

Graph[g, VertexCoordinates -> {{0, 0}, {0, 1}, {1, 1}, {1, 0}}, 
 VertexLabels -> Placed["Name", Center], VertexSize -> Medium, 
 EdgeShapeFunction -> 
  GraphElementData[{"CurvedArc", "Curvature" -> 0.5}]]

enter image description here

But I want that the edges separated by an offset from the vertices. Is there a simple way to control this within GraphElementData, similarly to how I could control the curvature? I want also an arrow but if I add "CarvedArrow", "ArrowSize" -> .1 to "CurvedArc", "Curvature" -> 0.5 MA does'nt display anything.

$\endgroup$
5
  • $\begingroup$ Where are your g? $\endgroup$
    – yode
    Nov 10, 2016 at 7:58
  • $\begingroup$ Please always put the code in a code block. Select the code with the mouse and press the {} button on the toolbar. I'm going to edit the post for you now, but please do this every time in the future when you post. I see several downvotes, no doubt the lack of formatting contributed to that (as well as the lack of a concrete g, which I'm going to also edit into the post now). $\endgroup$
    – Szabolcs
    Nov 10, 2016 at 9:15
  • $\begingroup$ Sorry not to have respected the standard I certainly was not correctly awaked. the graph was g = {a0 -> b0, b0 -> c0 , c0 -> d0, d0 -> a0}. Normaly I try to pay attention to this. I often fail. $\endgroup$ Nov 10, 2016 at 9:21
  • $\begingroup$ OK, so the adding CycleGraph was exactly what you meant then. $\endgroup$
    – Szabolcs
    Nov 10, 2016 at 9:43
  • $\begingroup$ Yes and the answer was perfect $\endgroup$ Nov 10, 2016 at 10:34

1 Answer 1

18
$\begingroup$
ClearAll[esF]
esF[setback_: .2, as_: .1] := {Arrowheads[as], 
    Arrow[GraphElementData[{"CurvedArc", "Curvature" -> 0.5}][##], setback]} &;

g0 = Graph[{a0 -> b0, b0 -> c0, c0 -> d0, d0 -> a0}, 
   VertexCoordinates -> {{0, 0}, {0, 1}, {1, 1}, {1, 0}}, 
   VertexLabels -> Placed["Name", Center], VertexSize -> Medium, 
   ImageSize -> 250];

SetProperty[g0, EdgeShapeFunction -> esF[]]

Mathematica graphics

Row[Labeled[SetProperty[g0, EdgeShapeFunction -> esF[#]], 
    "setback: " <> ToString[#], Top] & /@ {.2, {0, .2}, {.2, .4}}]

Mathematica graphics

Row[Labeled[SetProperty[g0, EdgeShapeFunction -> esF[.2, #]], 
    "size: " <> ToString[#], Top] & /@ {.1, .2, Small, Large}]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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