平滑的曲線段

平滑的曲線段

我需要曲線的最後一段(虛線)平滑地連接到前一段。請提出任何其他改進!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin {axis}[
    height=5cm, width=12cm,
    xmin=-6, xmax=21, ymin=0, ymax=6, 
   xlabel={}, 
    ylabel={trade effect}, 
    ylabel style={align=center}, 
    axis x line=bottom, axis y line = left, 
    axis line style={-latex, thick},
    xticklabels={,,}, yticklabels={,,},
    ytick=\empty,
    xtick={-5,0,5,10,15},
    xticklabels={$t_{a}$,$t_{b}$,$t_{c}$,$t_{d}$,$t_{e}$},
    ]
\addplot [mark=none, line width=.8pt, smooth]coordinates {
    (-5,0) (0,1)(5,4) (10,5) (15,5)};
\addplot[mark=none, line width=.8pt, smooth, dashed] coordinates {
    (15,5) (20,4)};
\addplot[mark=none, dashed] coordinates {(0,0) (0,6)};
\addplot[mark=none, dashed] coordinates {(5,0) (5,6)};
\addplot[mark=none, dashed] coordinates {(10,0) (10,6)};
\addplot[mark=none, dashed] coordinates {(15,0) (15,6)};
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

答案1

只需繪製兩次圖,一次是實線,一次是虛線,然後在每次的目標域上進行剪輯。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin {axis}[
    height=5cm, width=12cm,
    xmin=-6, xmax=21, ymin=0, ymax=6, 
   xlabel={}, 
    ylabel={trade effect}, 
    ylabel style={align=center}, 
    axis x line=bottom, axis y line = left, 
    axis line style={-latex, thick},
    xticklabels={,,}, yticklabels={,,},
    ytick=\empty,
    xtick={-5,0,5,10,15},
    xticklabels={$t_{a}$,$t_{b}$,$t_{c}$,$t_{d}$,$t_{e}$},
    ]
\begin{scope}   
\clip (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymin})
 rectangle (15,\pgfkeysvalueof{/pgfplots/ymax});
\addplot [mark=none, line width=.8pt, smooth] coordinates {
    (-5,0) (0,1)(5,4) (10,5) (15,5) (20,4)};
\end{scope} 
\begin{scope}   
\clip (15,\pgfkeysvalueof{/pgfplots/ymin})
 rectangle (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
\addplot [mark=none, line width=.8pt, smooth,dashed] coordinates {
    (-5,0) (0,1)(5,4) (10,5) (15,5) (20,4)};
\end{scope} 
\addplot[mark=none, dashed] coordinates {(0,0) (0,6)};
\addplot[mark=none, dashed] coordinates {(5,0) (5,6)};
\addplot[mark=none, dashed] coordinates {(10,0) (10,6)};
\addplot[mark=none, dashed] coordinates {(15,0) (15,6)};
\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容