So, your input is a 2d function f(x,y) and its surface, and you want to see its trace through z=0. This can be accomplished by means of a contour plot with level 0.
Here is a solution:

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%
\begin{document}
\thispagestyle{empty}
%
Initial \TeX{}t
\begin{figure}[h]
\begin{centering}
\begin{tikzpicture}
\tikzset{%
small dot/.style={fill=cyan,circle,scale=0.25}%
}
\begin{axis}[%
grid=major,
colormap/cool,
zlabel=$z$,
zmin=-5,
ztick={-5,-2.5,0,2.5,5},
ytick={-5,-2.5,0,2.5,5},
zmax=5,
xmin=-5,
xmax=5,
xlabel=$x$,
ylabel=$y$%
]
\addplot3 [surf] {0};
\addplot3[contour gnuplot={labels=false,levels={0},draw color=blue},domain=-4:4]
{exp(-x^2 -0.3*y^2 -0.2*x*y)*5- 0.1};
%
\end{axis}
\end{tikzpicture}
\par
\end{centering}
\caption{Funzione definita $f_{1}(x,y)$ o $z_{1}$}
\end{figure}
\par
Ending \TeX{}t
%
\end{document}
I took the freedom to discard the blue cross to show only the contour plot fragment. Note that I used some random surface which came to my mind, but any expression or table data is suitable here.
This example requires gnuplot
as pgfplots
is unable to compute the contour levels on its own. Consequently, you need to run it with -shell-escape
(like pdflatex -shell-escape <file.tex>
).
The argument labels=false
deactivates contour text labels, the levels
key chooses the requested contour levels (accepts a list), and draw color
is necessary because otherwise, the current colormap
would be used which is inadequate in this context.
EDIT the following is OPTIONAL.
For the records, here is my earlier (mis)understanding of the request. It addresses a slighty different use-case, namely one in which the 1d contour is given and the question is how to position it correctly.
From what I understand, you are given some 1d function f(x) which is given either as math expression (your example with sin(x)) or perhaps as data table, right? And you want that to be plotted into a 3D plane which happens to be orthogonal to one of the cube faces?
In this case, you can use either a parametric plot (if the function is to be sampled) or reorder the columns if the plot function is given as data table.
Here is your example with modifications:

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%
\begin{document}
\thispagestyle{empty}
%
Initial \TeX{}t
\begin{figure}[h]
\begin{centering}
\begin{tikzpicture}
\tikzset{%
small dot/.style={fill=cyan,circle,scale=0.25}%
}
\begin{axis}[%
grid=major,
colormap/cool,
zlabel=$z$,
zmin=-5,
ztick={-5,-2.5,0,2.5,5},
ytick={-5,-2.5,0,2.5,5},
zmax=5,
xmin=-5,
xmax=5,
xlabel=$x$,
ylabel=$y$%
]
\addplot3[green] table[x=X,y expr=5,z=Y]
{
X Y
-5 5
-4 -1
-3 0
-2 1
-1 1.2
0 1
1 2
2 3
4 1
5 0
};
\addplot3 [surf] {0};
\addplot3 [color=blue] coordinates {(0,-5,0) (0,5,0)};
\addplot3 [color=blue] coordinates {(-5,0,0) (5,0,0)};
\node[small dot,pin=-60:{$z_1$}] at (axis cs:2.5,-5,0) {};
\addplot3[red,samples y=1]
(x,{4*sin(deg(x))},0);
%
\end{axis}
\end{tikzpicture}
\par
\end{centering}
\caption{Funzione definita $f_{1}(x,y)$ o $z_{1}$}
\end{figure}
\par
Ending \TeX{}t
%
\end{document}
The red
plot is a parametric plot; you see that I provided x,y,and z coordinate values explicitly, z being zero here due to the z=0 plane. Note that samples y=1
is required because \addplot3 {<expression>}
always samples a 2d function f(x,y). If we say samples y=1
, we tell pgfplots
that it actually has just one coordinate, i.e. that it should sample a line although it is a 3d plot.
The green
plot is a table plot in which I mapped the table's two columns X
and Y
to the plane y=5
. Note that the ordering of plots is important.
Is this what you had in mind?