Plot a function of two variables equal 0

I would like to plot the function x2(1 − x2) − y2 = 0 in LaTeX.

I tried running following code

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
view={0}{90},
no markers,
]

contour gnuplot={
levels=0,
labels=false,
}
]
{x^2(1-x^2)-y^2};

\end{axis}
\end{tikzpicture}

\end{document}


but the output is

But should be

Thanks for helping.

New contributor
Aris Martin Accola is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

@Superuser27 is correct about the missing *. Additionally, I don't understand why you're using \addplot3. Finally, that's not a function.

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
]
\draw (axis cs:1,-0.07,1)--(axis cs:1,0.07);
\end{axis}
\end{tikzpicture}

\end{document}

• I used addplot for the contour gnuplot. So i don‘t have to calculate the function equal 0 for y. – Aris Martin Accola Mar 15 at 14:44

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
]
\end{axis}
\end{tikzpicture}

\end{document}


• Best answer.... – JPi 2 days ago

I had some trouble running your code (compatibility issues) but now it should work. I think the answer is simply that you missed a * in {x^2(1-x^2)-y^2};.

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm}
\pgfplotsset{compat=1.15}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
no markers,
]
contour gnuplot={
levels=0,
labels = false,
},
domain=-2:2,
domain y=-1.3:1.3,
]
{x^2*(1-x^2)-y^2};

\end{axis}
\end{tikzpicture}
\end{document}

• how did you manage to compile it, I am having hard-time compiling it with the error being: Package pgfplots Error: sorry, plot file{texstudio_Ml6192_contourtmp0.table} could not be opened. {x^2*(1-x^2)-y^2};. If you have some idea, let me know. – Raaja Mar 14 at 13:24
• I got the same error. I had to look around online and found that Overleaf also complains but still gives you an output. @Raaja – Superuser27 Mar 14 at 13:27
• Huhhh, I see. Thanks for the update! – Raaja Mar 14 at 13:28
• Usually x^2 is implemented using exp(2*log(x)) which can't handle negative numbers. – John Kormylo Mar 14 at 13:55
• @Raaja I had the same problem first compiling it on my computer. So make sure you have installed gnuplot on your computer and then you need to add it to your path so that the program can find gnuplot. You also need to enable —shell-escape. – Aris Martin Accola Mar 15 at 14:41