3

I want to plot the region of 0 < x2 - y2 <= 1.

I have done it in WolframAlpha, and it shows like ....

Enter image description here

How can I plot the above in LaTeX?

2
  • 4
    You should have a look at the pgfplots package. It has an excellent manual that will get you started. Once you have dug into it a bit, you can come back should you have more specific questions :) The manual can be found at ftp.fau.de/ctan/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf
    – Raven
    Jul 23 at 8:46
  • 1
    By the way: The plot from WA is quite ugly. It tries to camouflage the symmetries of the area. Jul 23 at 9:01
9

You could do if whit pgfplots as Raven suggests or with tikz (there are more options too) as in my example.

I use a \foreach command because the region to plot and the curves are both symmetric, so I avoid repeated code.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \def\xmax{4};
  % grid
  \draw[help lines] (-\xmax,-\xmax) grid (\xmax,\xmax);
  % axes
  \draw[-latex] (-\xmax,0) -- (\xmax,0) node [right] {$x$};
  \draw[-latex] (0,-\xmax) -- (0,\xmax) node [above] {$y$};
  % a little bit of the hyperbola goes out of the grid so I'm clipping it
  \clip (-\xmax,-\xmax) rectangle (\xmax,\xmax);
  \foreach\i in {-1,1} % to draw the following twice
  {%
    \draw[thick,blue,fill=yellow,fill opacity=0.4] (0,0) -- (\i*\xmax,-\xmax)
          -- plot[smooth,domain=-\xmax:\xmax] ({\i*sqrt(1+\x*\x)},\x)
          -- (\i*\xmax,\xmax) -- cycle;                                   % curve(s) and yellow regoin(s)
    \draw[thick,red] (\i*\xmax,-\xmax) -- (0,0) --  (\i*\xmax,\xmax);     % asymptote(s)
  }
\end{tikzpicture}
\end{document}

enter image description here Edit: I changed the code a little bit, drawing the curve and filling the region at the same time.

5

If you compile this:

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}[scale=4]
    \filldraw[fill=cyan,draw=black,domain={-sqrt(3)}:{sqrt(3)},variable=\y,samples=100]
      (2,-{sqrt(3)})--(2,-2)--plot({sqrt(\y*\y+1)},\y)--(2,2)--(0,0)--(2,-2)--cycle;
    \filldraw[fill=cyan,draw=black,domain={-sqrt(3)}:{sqrt(3)},variable=\y,samples=100]
      (-2,-{sqrt(3)})--(-2,-2)--plot({-sqrt(\y*\y+1)},\y)--(-2,2)--(0,0)--(-2,-2)--cycle;
  \end{tikzpicture}    
\end{document}

you will get this:

enter image description here

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.