# How to control the points of splines?

**URL:** <https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087>\
**Category:** Help\
**Created:** [March 24, 2022, 8:52am UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087 "2022-03-24T08:52:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexrt](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alexrt](https://forum.graphviz.org/u/Alexrt)\
**Post date:** [March 24, 2022, 8:52am UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/1 "2022-03-24T08:52:50Z")

</div>

Hi, all.

The documentation of “splineType” as follows.

# splineType

`spline ( ';' spline )*`

- where `spline` = `(endp)? (startp)? point (triple)+`
- and `triple` = `point point point`
- and `endp` = `"e,%f,%f"`
- and `startp` = `"s,%f,%f"`

If a spline has points p₁ p₂ p₃ … pₙ, (n = 1 (mod 3)), the points correspond to the control points of a cubic B-spline from p₁ to pₙ. If startp is given, it touches one node of the edge, and the arrowhead goes from p₁ to startp. If startp is not given, p₁ touches a node. Similarly for pₙ and endp.

But the following codes don’t work.

#python3.6  
dot = Digraph()  
dot.attr(rankdir=‘LR’)  
dot.graph\_attr[‘layout’] = ‘fdp’  
dot.graph\_attr[‘splines’] = ‘curved’

dot.node(‘A’, ‘A’, shape = ‘doublecircle’, pos=‘0,0!’)  
dot.node(‘B’, ‘B’, shape = ‘doublecircle’, fontsize=‘8’, height=‘1’,pos=‘2,0!’)

dot.edge(‘A’,‘B’,‘C’,pos=“spline(”(e,2,1);(s,0,1);(1.1,1.1);(1.2,1.2);(1.3,1.3)")

And the result I want just like this.

 ![image](https://global.discourse-cdn.com/graphviz/original/1X/2b9d111b992b9eee8e0d5c7917dcfb359f414d95.png)

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [March 24, 2022, 3:27pm UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/2 "2022-03-24T15:27:41Z")

</div>

(I am not a mathematician, bear with me) (splines are a major source of heartburn)  
I think you are missing a point - you need four.  
Ignoring the optional “start” and “end” points that define arrowheads, a spline needs _four_ points followed by zero or more sets of three points or `spline = (endp)? (startp)? POINT (triple)+`. (note POINT)  
Each generated spline segment needs four points. When considering triples, the last point in the previous set is used as the fourth point. (poorly worded).  
Note that the spline points are NOT “draw a curve through these points”. For a non-mathematician (me) spline points are “draw a curve using these points in a magical/mathematical way that does not touch, but uses them for guidance”.  
Graphviz seems to usually generate 7 (4 then 3) points for simple curves (ignoring arrowheads), but 4 points work fine.  
See also: [Fun with edges!](https://forum.graphviz.org/t/fun-with-edges/888)

---

<div class="post-metadata">

**Author:** ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)\
**Post date:** [March 25, 2022, 2:24am UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/3 "2022-03-25T02:24:01Z")

</div>

Yes, exactly. We were targeting Postscript’s piecewise cubic Bézier curves which as you say always have 4 + 3n points.

---

<div class="post-metadata">

**Author:** ![Alexrt](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alexrt](https://forum.graphviz.org/u/Alexrt)\
**Post date:** [March 27, 2022, 8:09am UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/4 "2022-03-27T08:09:22Z")

</div>

Thank you very much for your reply. I 've learn a lot from your article  
Fun with edges! (bear with my poor coding I can’t get the method you guide the spline crying…)

And I still have a problem when use Graphviz in python.

Here is my code.

#Python3.6  
dot1 = Digraph(“1”)  
dot1.attr(rankdir=‘LR’)  
dot1.graph\_attr[‘layout’] = ‘neato’ #fdp,neato  
dot1.graph\_attr[‘splines’] = ‘true’ #compound,curved,true

dot1.node(‘a’,shape=“point”,pos=“0,0!”,color=“blue”)  
dot1.node(‘b’,shape=“point”,pos=“10,0!”,color=“green”)  
dot1.node(‘c’,shape=“point”,pos=“5,5!”,color=“red”)

dot1.edge(‘a’,‘b’,pos=‘10,0 0,0 1,1 2,2 3,3 5,5 7,3 8,2 9,1’) #It doesn’t work.

dot1.view()

I have tried  
“dot1.edge(‘a’,‘b’,pos=‘10,0 0,0 1,1 2,2 3,3 5,5 7,3 8,2 9,1’)”  
“dot1.edge(‘a’,‘b’,pos=‘e,10,0 s,0,0 1,1 2,2 3,3 5,5 7,3 8,2 9,1’)”  
in python, but they don’t work neither.

Do you know the correct expression to guide the spline in python?  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Alexrt](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Alexrt](https://forum.graphviz.org/u/Alexrt)\
**Post date:** [March 27, 2022, 8:12am UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/5 "2022-03-27T08:12:34Z")

</div>

Do you know the correct expression to guide the spline in python?  
Thank you very much!

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [March 27, 2022, 4:02pm UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/6 "2022-03-27T16:02:42Z")

</div>

I do not use Python to generate Graphviz code, so just guessing:

- What does `don’t work` mean? Error message, no edge, weird edge, …?
- expect this to fail: not 4,7, or 10 points: `dot1.edge(‘a’,‘b’,pos=‘10,0 0,0 1,1 2,2 3,3 5,5 7,3 8,2 9,1’)`
- expect this to be OK (7 points + e & s) `dot1.edge(‘a’,‘b’,pos=‘e,10,0 s,0,0 1,1 2,2 3,3 5,5 7,3 8,2 9,1’)`

Best guess, you are missing the `-n2` commandline option for neato - see [FAQ | Graphviz](https://graphviz.org/faq/#FaqDotWithCoords) and [pos | Graphviz](https://graphviz.org/docs/attrs/pos/)

---

<div class="post-metadata">

**Author:** ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)\
**Post date:** [March 27, 2022, 4:45pm UTC](https://forum.graphviz.org/t/how-to-control-the-points-of-splines/1087/7 "2022-03-27T16:45:16Z")

</div>

In python you would need a specific graphics or plotting library. matplotlib already has cubic Beziers. See for example [Path Tutorial — Matplotlib 3.6.3 documentation](https://matplotlib.org/stable/tutorials/advanced/path_tutorial.html)
