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



\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    domain=-5:5, samples=201,
    restrict y to domain=-5:5,
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
\addplot[samples=501,domain=-0.7854:0.7854,blue] {};

  • 1
    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.



\addplot3 [
    very thick,
    contour gnuplot={
        draw color=black
] {x^2*y + x*y^2};

| improve this answer | |
  • What does "view={0}{90}" specify about the axes? How about "levels=1"? – Adelyn Oct 26 '14 at 18:19
  • 1
    @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
  • 1
    @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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