如何在 pgfplots 中的图表中添加开放点?

如何在 pgfplots 中的图表中添加开放点?

我希望在 $x=0$ 处出现不连续性,然后将两个图拼接在一起。但结果并不像我希望的那样。

\documentclass[border=6pt]{standalone}
\usepackage{pgfplots}

\pgfmathdeclarefunction{myfncA}{1}{\pgfmathparse{ (#1-1)^2+1}}
\pgfmathdeclarefunction{myfncB}{1}{\pgfmathparse{ -(#1+1)^2+3}}

\pgfplotsset{every axis/.append style={
    font=\scriptsize,
    x=.75cm,
    y=.75cm,    
    axis x line=center,
    axis y line=center,
    x axis line style={<->},
    y axis line style={<->},
    xtick={-5,-4,...,5},
    ytick={-5,-4,...,5},
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below},
    ylabel style={left},
    xmin=-5.5, xmax=5.5,
    ymin=-5.5, ymax=5.5,
    }
}

\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[>=latex]
\begin{axis}
  \addplot[domain=0:3, blue, samples=50,ultra thick,arrows={Circle[open]->}] {myfncA(x)};
  \addplot[domain=-3.9:0, blue, samples=50,ultra thick,arrows=<-{Circle[open]}] {myfncB(x)};
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

也许明确地画出差距就可以了?

\documentclass[border=6pt,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfmathdeclarefunction{myfncA}{1}{\pgfmathparse{ (#1-1)^2+1}}
\pgfmathdeclarefunction{myfncB}{1}{\pgfmathparse{ -(#1+1)^2+3}}

\pgfplotsset{every axis/.append style={
    font=\scriptsize,
    x=.75cm,
    y=.75cm,    
    axis x line=center,
    axis y line=center,
    x axis line style={<->},
    y axis line style={<->},
    xtick={-5,-4,...,5},
    ytick={-5,-4,...,5},
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below},
    ylabel style={left},
    xmin=-5.5, xmax=5.5,
    ymin=-5.5, ymax=5.5,
    }
}

%\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[>=latex]
\begin{axis}[myplot/.style={samples=50,blue,->,ultra thick}]
  \addplot[domain=0:3,myplot] {myfncA(x)};
  \addplot[domain=0:-3.9,myplot] {myfncB(x)};
  \fill[white,draw=blue,thick](axis cs:0,{myfncA(0)})circle[radius=2pt];% drawing the gap
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容