# How can I plot in LaTeX?

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

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

How can I plot the above in LaTeX?

• 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 Jul 23 at 8:46
• By the way: The plot from WA is quite ugly. It tries to camouflage the symmetries of the area. Jul 23 at 9:01

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}


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

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: