我有以下分段函数
其图形由
问题 1。如何绘制与中间部分未正确绘制相对应的表面?
问题2. 我们如何才能将 $z$ 轴的刻度和标签移动到另一侧?
我按照以下方式绘制该函数。
\documentclass[a4paper,12pt]{article}
%\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
baseline=(origin),
declare function={
f(\t,\y)=(y<=0)*2*\t+(\t>0)*(\y>\t)*(\y<=\t^2)*2*(1-\y/\t)*\t+(\y>=\t^2)*(-2)*\t;
}
]
\begin{axis}[
width=100mm,
height=60mm,
view={135}{45},
xmin=0,
xmax=1,
xlabel={$t$},
ymin=-1,
ymax=1,
ylabel={$y$},
zmin=-2,
zmax=2,
zlabel={$z$},
zlabel style={rotate=-90},
]
\coordinate (origin) at (axis cs:0,0,0);
\addplot3[surf,color=blue,opacity=0.5,domain=0:1,y domain=-1:1,faceted color=blue]{f(\x,\y)};
\draw[variable=\t,domain=0:1,color=red,thick] plot (axis cs:\t,0,{2*\t});
\draw[variable=\t,domain=0:1,color=red,thick] plot (axis cs:\t,{\t^2},{(-2)*\t});
\end{axis}
\end{tikzpicture}
\caption{Graphic of $f:[0,1]\times[-1,1]\to[-2,2]$.}
\end{figure}
\end{document}
答案1
我得到了以下近似解。
\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[baseline=(origin)]
\begin{axis}[
width=100mm,
height=60mm,
view={135}{45},
xmin=0,
xmax=1,
xlabel={$t$},
ymin=-1,
ymax=1,
ylabel={$y$},
zmin=-2,
zmax=2,
zlabel={$z$},
zlabel style={rotate=-90},
]
\coordinate (origin) at (axis cs:0,0,0);
\fill[color=blue] (axis cs:0,0,0)
-- (axis cs:0,-1,0)
-- (axis cs:1,-1,2)
-- (axis cs:1,0,2)
-- cycle;
\fill[color=blue] (axis cs:0,0,0)
\foreach \pt in {0.1,0.2,...,1}{ -- (axis cs:\pt,0,{2*\pt})}
\foreach \pt in {1,0.9,...,0}{ -- (axis cs:\pt,{\pt^2},{(-2)*\pt})};
\fill[color=blue] (axis cs:0,0,0) -- (axis cs:0,1,0) -- (axis cs:1,1,-2)
\foreach \pt in {1,0.9,...,0}{ -- (axis cs:\pt,{\pt^2},{(-2)*\pt})};
\draw[variable=\t,domain=0:1,color=red,thick] plot (axis cs:\t,0,{2*\t});
\draw[variable=\t,domain=0:1,color=red,thick] plot (axis cs:\t,{\t^2},{(-2)*\t});
\end{axis}
\end{tikzpicture}
\caption{Graphic of $f:[0,1]\times[-1,1]\to[-2,2]$.}
\end{figure}
\end{document}