[Tex/LaTex] Plot function with 2 variables in tikz / pgfplots

pgfplotstikz-pgf

Using Tikz / pgfplots, how can you plot a function with two variables, such as:
|x| + |y| <= 1 / sqrt(2)?

If the function only had one input,X, it is easy to plot:

\begin{figure}[!hb]
\centering
\begin{tikzpicture}[scale=1.0]
\begin{axis}
    \addplot[domain=-10000:10000, blue, ultra thick] {abs(x)};
    \end{axis}
\end{tikzpicture}
\caption{Plot of $\abs(x)$}
\end{figure}

However, the following produces an error

\addplot[domain=-10000:10000, blue, ultra thick] {abs(x) + abs(y) <= 1 / sqrt(2)};

Best Answer

You can use a parametrization (well, two in this case):

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
domain=-1/sqrt(2):1/sqrt(2),
samples=400,
xmin=-1.5,
xmax=1.5,
ymin=-1.5,
ymax=1.5,
axis on top=true
]
\addplot+[mark=none,cyan,fill] ({x},{max(1/sqrt(2)-abs(x),0)}) \closedcycle;
\addplot+[mark=none,cyan,fill] ({x},{min(abs(x)-1/sqrt(2),0)}) \closedcycle;
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here