I'm trying to automate drawing filled plots along (mostly straight) paths. A simple example of what I'm trying to achieve:



            every path/.style={thick, red ,fill, fill opacity=.5},
            every plot/.style={smooth}]

            \draw (0,1) -- plot[domain=0:5, shift={(0,1)}, rotate={atan(3/4)}] (\x,0.05*\x^2) -- (4,4) -- cycle;
            \draw[black] (0,1) -- (4,4);

            \draw (0,3) -- plot[domain=0:sqrt(17), shift={(0,3)}, rotate={atan(-1/4)}] (\x,{0.5*sin(3*\x r)}) -- (4,2) -- cycle;
            \draw[black] (0,3) -- (4,2);

Expected Result

But how can I automate the process (maybe even for curved paths?) How can I

  • Shift the plot to the last coordinate (I tried it with \pgfextractxy, but was not able to get it to work)
  • Rotate it (Works quite ok with the atan(), but what about vertical paths?)
  • Set the domain to the length of the path (Tried it with the let-option and the veclen command, but I got the "dimension too large"-error)
  • Have it implemented, so that I can repeat it many times (e.g. \draw (A) -- plot[on path] (\x, <function>) -- (B))

Any ideas are appreciated!


As it seems that my intentions were not very clear: At the moment I would be happy with a solution for straight paths only. (The option for curved paths would be nice to have, though) So my goal is to have a simple method plotting a function between two given points on the canvas without having to recalculate my rotation, shift and domain every time.

  • How. Can. I. Plot. On. A. Curved. Path. ?. – user156344 May 22 at 8:32
  • I‘m sorry, but I don‘t understand, what you want to tell me with your comment. @JouleV – Wulle May 22 at 8:48
  • How can I plot a e.g. x ^2 curve on a curve? – user156344 May 22 at 8:49
  • 1
    Unfortunately I don‘t know the english equivalent but there is a Wikipedia article in German: de.m.wikipedia.org/wiki/Krummlinige_Koordinaten . You can think of the y axis moving along the path in a way that it always stands orthogonal to the tangent (x axis) – Wulle May 22 at 8:54
  • But ploting along curved paths is not necessary! I would also be happy with straight paths! – Wulle May 22 at 8:55

This plots along straight lines.



            every path/.style={thick, red ,fill, fill opacity=.5},
            every plot/.style={smooth},
            plot along line/.style args={from #1 to #2}{insert
            let \p1=($#2-#1$),\n1={veclen(\x1,\y1)/1cm},\n2={atan2(\y1,\x1)}
            in   [shift={#1},rotate=\n2,domain=0:\n1]

            \draw {[plot along line=from {(0,1)} to {(4,4)}] 
            plot (\x,0.05*\x^2) }-- (4,4) -- cycle;
            \draw[black] (0,1) -- (4,4);

            \draw[plot along line=from {(0,3)} to {(4,2)}] plot (\x,{0.5*sin(3*\x r)})
            coordinate (end) --cycle;
            \draw[black] (0,3) -- (end);

enter image description here

You can also add styles that plot along curved coordinate systems, using \usepgfmodule{nonlineartransformations} \usepgflibrary{curvilinear}.


  \draw [help lines] (0,0) grid (3,2);
\draw (0,-30pt) grid [step=10pt] (80pt,30pt); 
\draw[blue,thick] plot[domain=0:2.8,samples=51] ({\x},{sin(180*\x)});
  \draw[red, very thick]
    (0mm,20mm) .. controls (11mm,20mm) and (20mm,11mm) .. (20mm,0mm);

enter image description here

This example is more or less taken from the pgfmanual except that I added a plot of a function. However, I do not know what precisely you expect to be done? How do you specify the coordinate system?

  • This is exactly what I was searching for. I think the second example is perfect, as I wanted to plot a function along a half circle. Thank you! – Wulle May 23 at 5:07

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.