Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wanted to have a discontinuity at $x=0$ where I spliced together the two graphs. But things aren't visually working out the way I wanted them to.

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

enter image description here

share|improve this question
3  
How did you want them to work out? –  Torbjørn T. May 30 at 7:15

1 Answer 1

up vote 3 down vote accepted

Maybe it is ok to draw the gap explicitly?

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

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.