I want to be able to plot in a 3D environment any type of function of two variables z = f(x,y), where x and y are specified within a given range. For instance plot f(x,y) = x^2 + y^2 where x in [-2,2] and y in [-2,2] as a "wireframe" surface plot. I want this plot to go on the rectangle (defined in the same coordinate system) that I have drawn, without the axis labels. How can this be done
\documentclass[border=10pt,varwidth]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{pgfplots}
\pgfplotsset{
every axis/.append style = {thick},tick style = {thick,black},
%
% #1 = x, y, or z
% #2 = the shift value
/tikz/normal shift/.code 2 args = {%
\pgftransformshift{%
\pgfpointscale{#2}{\pgfplotspointouternormalvectorofticklabelaxis{#1}}%
}%
},%
%
range3frame/.style = {
tick align = outside,
scaled ticks = false,
enlargelimits = false,
ticklabel shift = {10pt},
axis lines* = left,
line cap = round,
clip = false,
xtick style = {normal shift={x}{10pt}},
ytick style = {normal shift={y}{10pt}},
ztick style = {normal shift={z}{10pt}},
x axis line style = {normal shift={x}{10pt}},
y axis line style = {normal shift={y}{10pt}},
z axis line style = {normal shift={z}{10pt}},
}
}
\begin{document}
% ----- First plot
\tdplotsetmaincoords{70}{155}
\begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick},
vector/.style={-stealth,black,very thick},
vector guide/.style={dotted,black,thick},
]
%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,-0.5,0);
%tikz-3dplot coordinate definition using r, theta, phi coords
\pgfmathsetmacro{\ax}{1}
\pgfmathsetmacro{\ay}{-1}
\pgfmathsetmacro{\az}{0.5}
\coordinate (P) at (\ax,\ay,\az){};
%draw axes
\draw[axis] (0,-0.5,0) -- (2,-0.5,0) node[anchor=north east]{$y$}; % x-axis becomes y axis
\draw[axis] (0,-0.5,0) -- (0,-2,0) node[anchor=south]{$x$}; %minius y-axis becomes positive x axis
\draw[axis] (0,-0.5,0) -- (0,-0.5,2) node[anchor=south]{$z$};
\draw[thick,tdplot_main_coords] (1.5,0.5,0)-- (1.5,-0.5,0) -- (-1.5,-0.5,0)--(-1.5,0.5,0)--cycle;
\begin{axis}[range3frame, view={55}{45}]
\addplot3[surf, colormap/hot2, samples=41, domain=0:2] {0.1*(x^2+y^2)};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
How about this
It will need some fine tuning, but it basically works.
I slightly changed it by adding
axis lines=none
in order to hide the axis lines. It is still a bit ugly, but I don't usepgfplots
regularly, so I am not very used to the styling possibilities it offers.