# controlling the angle of line/curve endings

Is there a way to control the line endings of a line/curve to be vertical. It is easier to explain with a picture. Here I have drawn a curve, but as you can see the lines end at the angle equal to the gradient of the curve at that point. I want it to end vertically so that it looks like the line is truncated where the axes end:

\begin{tikzpicture}[scale=1]
\draw[line width=20pt, red] plot [smooth,tension=1] coordinates{(-1,0.5) (0,1.5) (1,1.5) (2,2.4) (3,2) (4,2.2)};
\draw[thick] plot [smooth,tension=1] coordinates{(-1,0.5) (0,1.5) (1,1.5) (2,2.4) (3,2) (4,2.2)};
\draw [->, black, ultra thick] (-1,0) -- (4,0);
\draw [->, black, ultra thick] (0,-1) -- (0,4);
\end{tikzpicture}


Here's the code

One easy option is to clip the ends:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{scope}
\clip (-0.71,-1) rectangle (3.82,4);
\draw[line width=20pt, red] plot [smooth,tension=1] coordinates{(-1,0.5) (0,1.5) (1,1.5)
(2,2.4)(3,2) (4,2.2)};
\draw[thick] plot [smooth,tension=1] coordinates{(-1,0.5) (0,1.5) (1,1.5) (2,2.4) (3,2)
(4,2.2)};
\end{scope}
\draw [->, black, ultra thick] (-1,0) -- (4,0);
\draw [->, black, ultra thick] (0,-1) -- (0,4);
\end{tikzpicture}
\end{document}


If you want the axes behind the curve, draw them first:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw [->, black, ultra thick] (-1,0) -- (4,0);
\draw [->, black, ultra thick] (0,-1) -- (0,4);
\begin{scope}
\clip (-0.71,-1) rectangle (3.82,4);
\draw[line width=20pt, red] plot [smooth,tension=1] coordinates{(-1,0.5) (0,1.5) (1,1.5)
(2,2.4)(3,2) (4,2.2)};
\draw[thick] plot [smooth,tension=1] coordinates{(-1,0.5) (0,1.5) (1,1.5) (2,2.4) (3,2)
(4,2.2)};
\end{scope}
\end{tikzpicture}
\end{document}