策划一个情节,直到它碰到另一个情节

策划一个情节,直到它碰到另一个情节

以下是代码:

\begin{figure}[H]\centering
    \begin{tikzpicture}
        \begin{axis}[
            xmin=-4,xmax=4,
            ymin=-15,ymax=15,
            height = 5in,
            axis lines=center,
            axis line style=->, xlabel = {$x_1$}, ylabel={$x_2$},
            %axis equal,
            legend cell align = {left},
            every axis x label/.style={ at={(ticklabel* cs:1.05)},          anchor=west,},
            every axis y label/.style={at={(ticklabel* cs:1.05)},           anchor=south,}, 
            title= {Extremal Curves Problem 1},         title style={xshift=0, yshift=1.75em},
            domain=0:15,samples=300,legend pos=outer north east]
            \addplot[latex-][color = blue, thick, domain = 2:3] {-1 + (x + 1)^2};
            \addplot[latex-][color = blue, thick, domain = 1:2] {-1 + (x + 1)^2} node[below right, pos = 0.5, font = \small] {\(u^* = 1\)};
            \addplot[color = blue, thick, domain = 0:1] {-1 + (x + 1)^2};
            \addplot[-latex][color = red, thick, domain = -3:-2] {1 - (-x + 1)^2};
            \addplot[-latex][color = red, thick, domain = -2:-1] {1 - (-x + 1)^2} node[above left, pos = 0.5, font = \small] {\(u^* = -1\)};
            \addplot[color = red, thick, domain = -1:0] {1 - (-x + 1)^2};
            \addplot [color = red, thick, dashed, domain = 0:3, -latex] ({-1 + (4 + 1)*exp(-x)}, {-1 + (-15 + 1)*exp(-2*x)});
            \addplot [color = blue, thick, dashed, domain = 0:3, -latex] ({1 + (-4 - 1)*exp(-x)}, {1 + (15 - 1)*exp(-2*x)});
        \end{axis}
    \end{tikzpicture} 
    \caption{Extremal curves for problem 1. Note that the red curve is the fastest curve.}
\end{figure}

相应的输出如下:

在此处输入图片描述

编辑:我想制作一些类似虚线图的图,使得蓝色虚线图停止在蓝色实线图上,红色虚线图停止在红色实线图上,并且每个图中都有几个间距均匀的箭头。标准是,出现在实线上方的虚线图将为蓝色(例如,从 (-4, -2) 开始的图将为蓝色并转到蓝色实线),而出现在实线下方的虚线图将为红色(例如,从 (4, 2) 开始的图将为红色并转到红色实线)。有没有办法这样做pgfplots?我尝试了该\clip命令,但它只剪掉其中的一部分而不是全部。有没有办法解决这个问题?

答案1

您可以使用decorations.markings库添加箭头,并使用 pgfplots 库将一条路径停在另一条路径上fillbetween。这允许您访问相交路径的相交段。不幸的是,似乎无法轻松找到装饰路径的相交段,这就是为什么我单独添加用于相交段的路径。好处是用于相交的路径结合了蓝色和红色曲线。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{decorations.markings}
\tikzset{arrow marks/.style={postaction=decorate,decoration={markings,
 mark=between positions #1 and 1 step #1 with {\arrow{>}}}},
 arrow marks/.default=10pt}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        xmin=-4,xmax=4,
        ymin=-15,ymax=15,
        height = 5in,width=0.9\textwidth,
        axis lines=center,
        axis line style=->, xlabel = {$x_1$}, ylabel={$x_2$},
        %axis equal,
        legend cell align = {left},
        every axis x label/.style={ at={(ticklabel* cs:1.05)},          anchor=west,},
        every axis y label/.style={at={(ticklabel* cs:1.05)},           anchor=south,}, 
        title= {Extremal Curves Problem 1},         title style={xshift=0, yshift=1.75em},
        domain=0:15,samples=300,legend pos=outer north east]
        \addplot[->,>=latex,arrow marks=1cm,color = blue, thick, domain = 3:0,
        tips=proper] 
        {-1 + (x + 1)^2};
        \addplot[->,>=latex,arrow marks=1cm,tips=proper,
        color=red,thick, domain = -3:0] {1 - (-x + 1)^2};
        \addplot[draw=none,name path=second, domain = -3:3]
         {-sign(x)*(1 - (abs(x) + 1)^2)};
        \addplot[draw=none,name path=first,domain=0:3] 
        ({-1 + (2 + 1)*exp(-x)}, {-1 + (2 + 1)*exp(-2*x)});
        \draw [->,>=latex,orange,thick,arrow marks=1cm,
        intersection segments={of=first and second, sequence={A0},}];
    \end{axis}
\end{tikzpicture} 
\caption{Extremal curves for problem 1. Note that the red curve is the fastest
curve.}
\end{figure}
\end{document}

在此处输入图片描述

也可以使用它\clip来完善路径。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{decorations.markings}
\tikzset{arrow marks/.style={postaction=decorate,decoration={markings,
 mark=between positions #1 and 1 step #1 with {\arrow{>}}}},
 arrow marks/.default=10pt}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        xmin=-4,xmax=4,
        ymin=-15,ymax=15,
        height = 5in,width=0.9\textwidth,
        axis lines=center,
        axis line style=->, xlabel = {$x_1$}, ylabel={$x_2$},
        %axis equal,
        legend cell align = {left},
        every axis x label/.style={ at={(ticklabel* cs:1.05)},          anchor=west,},
        every axis y label/.style={at={(ticklabel* cs:1.05)},           anchor=south,}, 
        title= {Extremal Curves Problem 1},         title style={xshift=0, yshift=1.75em},
        domain=0:15,samples=300,legend pos=outer north east]
        \addplot[->,>=latex,arrow marks=1cm,color = blue, thick, domain = 3:0,
            tips=proper] 
        {-1 + (x + 1)^2};
        \addplot[->,>=latex,arrow marks=1cm,tips=proper,
            color=red,thick, domain = -3:0] {1 - (-x + 1)^2};
        \clip plot[variable=\x,domain=-3:3] 
        (\x,{-sign(\x)*(1 - pow(abs(\x) + 1,2))}) |-cycle;
        \addplot[->,>=latex,arrow marks=1cm,tips=proper,
            color=orange,thick,domain=0:3] 
        ({-1 + (2 + 1)*exp(-x)}, {-1 + (2 + 1)*exp(-2*x)});
    \end{axis}
\end{tikzpicture} 
\caption{Extremal curves for problem 1. Note that the red curve is the fastest
curve.}
\end{figure}
\end{document}

在此处输入图片描述

您还可以将箭头设置在图长度的某些部分。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{decorations.markings}
\tikzset{arrow marks/.style={postaction=decorate,decoration={markings,
 mark=between positions 1/#1 and 1-1/#1 step 1/#1 with {\arrow{>}}}},
 arrow marks/.default=5}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[tips=proper]
    \begin{axis}[
        xmin=-4,xmax=4,
        ymin=-15,ymax=15,
        height = 5in,width=0.9\textwidth,
        axis lines=center,
        axis line style=->, xlabel = {$x_1$}, ylabel={$x_2$},
        %axis equal,
        legend cell align = {left},
        every axis x label/.style={ at={(ticklabel* cs:1.05)},          anchor=west,},
        every axis y label/.style={at={(ticklabel* cs:1.05)},           anchor=south,}, 
        title= {Extremal Curves Problem 1},         title style={xshift=0, yshift=1.75em},
        domain=0:15,samples=300,legend pos=outer north east]
        \addplot[->,>=latex,arrow marks,color = blue, thick, domain = 3:0] 
        {-1 + (x + 1)^2};
        \addplot[->,>=latex,arrow marks,
            color=red,thick, domain = -3:0] {1 - (-x + 1)^2};
        \clip plot[variable=\x,domain=-3:3] 
        (\x,{-sign(\x)*(1 - pow(abs(\x) + 1,2))}) |-cycle;
        \addplot[->,>=latex,arrow marks,
            color=orange,thick,domain=0:3] 
        ({-1 + (2 + 1)*exp(-x)}, {-1 + (2 + 1)*exp(-2*x)});
    \end{axis}
\end{tikzpicture} 
\caption{Extremal curves for problem 1. Note that the red curve is the fastest
curve.}
\end{figure}
\end{document}

在此处输入图片描述

相关内容