2

Im trying to draw the following graph: |x − 1| + |y − 1| ≤ 1

This is what I have:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
 xlabel=$x$,
 ylabel={$y$}
] 
\addplot {|x−1|+|y−1|≤1}; 
\end{axis}
\end{tikzpicture}
\end{document}

However this doesn't work. Would anyone be able to suggest why?

Torbjørn T.
  • 206,688
  • 1
    Because that's not a function. The argument of addplot is supposed to be a function, e.g. log(x) – JPi Feb 23 '17 at 13:20

1 Answers1

2

I guess for this inequality it is simplest to provide the "corner" values as coordinates, close the path and fill it.

To prove the coordinates are right, have a look at the corresponding Wolfram Alpha result.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=$x$,
        ylabel={$y$},
        axis equal image=true,
    ]
        \addplot [fill=blue!25] coordinates { (0,1) (1,2) (2,1) (1,0) } --cycle;
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535