# Plotting a level curve

How do I get TikZ to plot the level curve x^{2}y + xy^{2} = 1?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
axis lines=middle,
xmin=-5,xmax=5,
domain=-5:5, samples=201,
xlabel=$x$,ylabel=$y$,
ymin=-5,ymax=5,
restrict y to domain=-5:5,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={\empty},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\end{axis}
\end{tikzpicture}

\end{document}

• A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – Andrew Swann Oct 26 '14 at 16:31
• could you please add a plot output you have from the code above? – Enthusiastic Engineer Oct 26 '14 at 17:04
• @EnthusiasticStudent There is no output of this code it's a MWE. – percusse Oct 26 '14 at 17:05
• @percusse MWE is the code the OP has developed till now? It may contain some output or not? Am I right? – Enthusiastic Engineer Oct 26 '14 at 17:06
• @EnthusiasticStudent Yes and you can see from the last addplot command that the function to be plotted is missing so gives only an axis. But it is useful so that we can directly copy paste and use it. – percusse Oct 26 '14 at 17:10

You can use the contour gnuplot functionality for this, which uses gnuplot as a backend for doing the actual calculations.

To compile the document, you need to have gnuplot installed on your system and shell escape must be enabled (e.g. pdflatex -shell-escape filename). PGFPlots makes the necessary gnuplot calls automatically.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={0}{90}]
very thick,
contour gnuplot={
levels=1,
labels=false,
draw color=black
},
samples=50
] {x^2*y + x*y^2};
\end{axis}
\end{tikzpicture}

\end{document}

• What does "view={0}{90}" specify about the axes? How about "levels=1"? – Adelyn Oct 26 '14 at 18:19
• @Adelyn: See p. 140 and p. 142 (in section 4.6.8 Contour Plots) of the manual. – Jake Oct 26 '14 at 18:23
• So, how can you compile this under MikTeX? – AboAmmar Oct 26 '14 at 18:24
• @AboAmmar: I'm not sure what you mean. Do you get an error message? – Jake Oct 26 '14 at 18:26
• @Jake I mean if you are running Windows 7 and you are using a usual editor like Texmaker, what is exactly required to get this compiled correctly? Or how to enable gnuplot? Because I get the error message: ! Package pgfplots Error: sorry, plot file{myFile_contourtmp0.table} could not be opened. – AboAmmar Oct 26 '14 at 21:41