4

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:

enter image description here

\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

1

1 Answer 1

4

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}

enter image description here

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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .