我怎样才能删除 pgfplots 中的这些不连续线?

我怎样才能删除 pgfplots 中的这些不连续线?

我正在策划这个:

在此处输入图片描述

唯一的问题:垂直不连续线。我不知道如何去除它们。我知道发生了什么,我让 pgfplots 为我画一些东西,但它不知道什么时候不画,所以它画了这些垂直线。我想避免必须定义每条彩色线的几个部分,因为这太费事了,此外,还要去掉代表零值的 x 轴上的线。有人知道怎么做吗?下面是图片的代码。

 \begin{tikzpicture}
\begin{axis}
    [%
    axis lines = center,ylabel=$\R$, xlabel= $X$, xlabel near ticks,xmin=-10,xmax=10,ymax=4, xtick=\empty, xticklabels=\empty
    ]
            
    \addplot[domain=-10:10,samples=250, name path=f, thick, color=blue]         {exp(-x^2/10)*abs(sin(deg(x^2))+x+1)};
                    \draw[black]  (5.21,1.5) node {$f$};
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=red]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<1.5,1<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),1,0)};     
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=orange]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<2,1.5<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),1.5,0)}; 
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=green]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<2.5,2<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),2,0)};   
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=purple]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<.5,.25<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),.25,0)};   

\end{axis}

\结束{tikzpicture}

答案1

添加jump mark left

在此处输入图片描述

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{intersections}%grrr
\pgfplotsset{compat=1.18}
\newcommand\R{R}%grrr
\begin{document}

 \begin{tikzpicture}
\begin{axis}
    [%
    axis lines = center,ylabel=$\R$, xlabel= $X$, xlabel near ticks,xmin=-10,xmax=10,ymax=4, xtick=\empty, xticklabels=\empty
    ]
            
    \addplot[domain=-10:10,samples=250, name path=f, thick, color=blue]         {exp(-x^2/10)*abs(sin(deg(x^2))+x+1)};
                    \draw[black]  (5.21,1.5) node {$f$};
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=red,jump mark left]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<1.5,1<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),1,0)};     
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=orange,jump mark left]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<2,1.5<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),1.5,0)}; 
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=green,jump mark left]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<2.5,2<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),2,0)};   
                    \addplot[domain=-10:10,samples=500, name path=f, thick, color=purple,jump mark left]{ifthenelse(and(exp(-x^2/10)*abs(sin(deg(x^2))+x+1)<.5,.25<exp(-x^2/10)*abs(sin(deg(x^2))+x+1)),.25,0)};   

\end{axis}

\end{tikzpicture}
\end{document}

相关内容