I would like to draw a function on a triangular domain using tikz. For example, I would like to draw the function x*y on (-1, -1) -- (-1, 1) -- (1, -1).
This is a MWE for the rectangular domain (-1, 1) x (-1, 1).
\documentclass[10pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=$x$,ylabel=$y$,small,view={120}{40}]
\addplot3[surf,domain=-1:1,domain y=-1:1] {x*y};
\end{axis}
\end{tikzpicture}
\end{document}
How can I draw this function only on a triangular part of the domain?
Cheers
Thank you for your replies.
One follow-up question: I noticed that when clipping several functions using addplot3, depending on the view, the plots often disappear. Consider e.g.
\documentclass[10pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=$x$,ylabel=$y$,small,view={-45}{10},zmin=-1,zmax=1]
\clip (axis cs:-1,-1) -- (axis cs:1,1) -- (axis cs:-1,1) -- cycle;
\addplot3[surf,domain=-1:1,domain y=-1:1,color=gray,faceted color=black,opacity=0.05] {x*y};
\addplot3[surf,domain=-1:1,domain y=-1:1,color=red,faceted color=red,opacity=0.05] {(2*x*x+2*x+2*y*y-2*y)/(2*x-2*y+4)};
\addplot3[patch,patch type=triangle,color=blue,faceted color=blue,fill opacity=0.2] coordinates {(-1,-1,1) (1,1,1) (-1,1,-1)};
\end{axis}
\end{tikzpicture}
\end{document}
If I change
view={-45}{10}
to
view={0}{90}
you can see the plots. However, with the aforementioned view, you cannot. Why is that?
Cheers

\documentclass...\begin{document}...\end{document}, it should compile and contain close to the minimal amount of code needed to explain/demonstrate what you are asking. This saves everyone time:) – Nov 20 '14 at 13:09@<username>(as in@HarishKumar) that user will be notified about the comment. – Nov 20 '14 at 23:49