So I managed to get this far with the knowledge I have of tikz and 3dplot and pgfplots :

\documentclass[11pt, oneside]{article}



    domain = -3:3,
    y domain = -2:2,
    view = {0}{90},
    colormap={violet}{rgb=(0.3,0.06,0.5), rgb=(0.9,0.9,0.85)},
    point meta max=5,
    point meta min=-5,

        contour filled={number = 100,labels={false}}, 
        ]{(\x)^2 - 4*(\y)^2};

\draw (0,-2) -- (0,2) node[left,yshift=-.2cm]{$y$};
\draw (-3,0) -- (3,0) node[below,xshift=-.2cm]{$x$};
\draw[color=gray!60!black,dashed] (-2,2) -- (2,-2);
\draw[color=gray!60!black,dashed] (-2,-2) -- (2,2);



Which yields out : output

Now to make it perfect, I would only need to add the lines to show the contour of the graph, more specifically the likes of x^2 - 4*y^2 = 1 and x^2 - 4*y^2 = 2. Now this is where I am stuck and don't know how to do it. It should look something like this though : final

Any help on this would be greatly appreciated and thanks in advance, also if I'm using the wrong tools to do what I want, you can always point me in the right direction.

P.S. I know the last picture looks odd, but I drew the lines in to show what it should resemble, though I would like it to represent the equations given above.


So this is what you are searching for? For details, please have a look at the comments in the code.

% used PGFPlots v1.15
        y domain=-2:2,
        point meta max=5,
        point meta min=-5,

        % changed how the surface is drawn
        % this is the "conventional" way to do so
        \addplot3 [
        ] {x^2 - 4 * y^2};

        % add the contour lines
        \addplot3 [
            % increase a bit the number of samples so `smooth' does a good job
            samples y=51,
            contour gnuplot={
                % state at which levels you want to draw the contour lines
                % we don't want to add labels
                % they should be drawn in black
                draw color=black,
                % and they should be smoothed
        ] {x^2 - 4 * y^2};

        \draw (0,-2) -- (0,2) node [left,yshift=-.2cm]{$y$};
        \draw (-3,0) -- (3,0) node [below,xshift=-.2cm]{$x$};
        \draw [color=gray!60!black,dashed] (-2,2) -- (2,-2);
        \draw [color=gray!60!black,dashed] (-2,-2) -- (2,2);


image showing the result of above code

  • Yes, this is exactly what I am looking for, though when I try to reproduce it gives me this error : Package pgfplots Error: sorry, plot file{test5_contourtmp0.table} could not be opened – Sephya Feb 16 '18 at 7:10
  • You need a working gnuplot installation for my solution to work. I guess that you don't have gnuplot installed, right? – Stefan Pinnow Feb 16 '18 at 7:34
  • 1
    ...and they also need to run with -shellescape or whatever is called in their LaTeX environment (I think) – Rmano Feb 16 '18 at 7:52
  • I do have gnuplot installed, though I don't know how to run the -shellescapte, I'll search on google for it – Sephya Feb 16 '18 at 8:03
  • 1
    That will depend on the operating system / LaTeX distribution you have. Try to start form here: tex.stackexchange.com/questions/99475/… – Rmano Feb 16 '18 at 8:08

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.