1

I have copied the code from this previous post about plotting elliptic curve, but unfortunately when the curve has two "parts", I can't figure out how to remove the connection between the two. Here is a MWE

\documentclass[12pt]{report}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.12,
    }
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1]
        \begin{axis}[
            xmin=-5,
            xmax=5,
            ymin=-5,
            ymax=5,
            xlabel={$x$},
            ylabel={$y$},
            scale only axis,
            axis lines=middle,
            domain=-1.912931:3,
            samples=200,
            smooth,
            clip=false,
            axis equal image=true,
        ]
            \addplot [black] {sqrt(x^3-2*x+1)};
            \addplot [black] {-sqrt(x^3-2*x+1)};
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

which yields

enter image description here

How do I remove the lines connecting the two segments?

NNN
  • 230
  • The function you plot has, unlike the example you refer to, a zero at one. Therefore the graphs touch each other. –  Apr 06 '18 at 19:09

1 Answers1

5

You could draw the two parts separately. The first from the first two roots and the second from the third root to whatever you like.

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.12,
        /pgf/declare function={
            f(\x) = sqrt(\x^3 - 2*\x +1);
            % roots of f(x)
            fA = -0.5 - sqrt(5)/2;
            fB = -0.5 + sqrt(5)/2;
            fC = 1;
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=-5,
        xmax=5,
        ymin=-5,
        ymax=5,
        xlabel={$x$},
        ylabel={$y$},
        scale only axis,
        axis lines=middle,
        samples=51,
        smooth,
        axis equal image=true,
    ]
        % left part
        \addplot [domain=fA:fB] {f(x)};
        \addplot [domain=fA:fB] {-f(x)};

        % right part
        \addplot [domain=fC:3] {f(x)};
        \addplot [domain=fC:3] {-f(x)};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535