控制线条/曲线末端的角度

控制线条/曲线末端的角度

有没有办法控制直线/曲线的线端垂直。用图片来解释更容易。这里我画了一条曲线,但你可以看到,线条以与该点曲线的斜率相等的角度结束。我希望它垂直结束,这样看起来就像线在轴结束的地方被截断了:

在此处输入图片描述

\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}

以下是代码

答案1

一个简单的选择就是剪掉发尾:

\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}

在此处输入图片描述

如果想要曲线后面的轴,请先绘制它们:

\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}

在此处输入图片描述

相关内容