平滑曲线段

平滑曲线段

我需要将曲线的最后一段(虚线)平滑地连接到前一段。请提出其他改进建议!

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

在此处输入图片描述

相关内容