我想绘制sqrt(-xy)
如果xy<=0
,以及-x^2+y
如果的图表xy>0
。
请考虑这个MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=2]
\begin{axis}[
legend pos=outer north east,
axis lines = center,
view={-35}{15},
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
zticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
zlabel = $z$,
legend style={cells={align=left}}
]
\addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:3,samples=40, samples y=20] {sqrt(-x*y)};
\addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:-3,samples=40, samples y=20] {sqrt(-x*y)};
\addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:3,samples=40, samples y=20] {-x*x+y};
\addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:-3,samples=40, samples y=20] {-x*x+y};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
我找不到好的视图来显示该功能x<0
。我觉得我喜欢从那里看到的景色y<0
,但图像很丑。你有什么推荐吗没有使用 gnuplot?
谢谢!
编辑。我还想绘制 7 个范数为 的向量1
:-平面上有 4 个xy
,和 方向上有 3 个x>0
。y>0
即:
在 中3D
。如果看起来复杂,您可以2D
像图片一样在 中进行操作。
答案1
这是个建议。手工绘制轴并隐藏必须隐藏的内容。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=2,
declare function={f(\x,\y)=ifthenelse(\x*\y<0,sqrt(-\x*\y),-\x*\x+\y);}]
\begin{axis}[hide axis,
legend pos=outer north east,
view={75}{45},clip=false
]
\draw[thick,-stealth] (0,0,0) -- (0,4,0) node[right]{$y$};
\addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
\addlegendentry{$f(x,y)$}
\draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
\draw[thick,-stealth] (0,0,0) -- (4,0,0) node[right]{$x$};
\end{axis}
\end{tikzpicture}
\end{document}
我认为,在正 xy 平面上绘制这些单位向量的任何尝试看起来都不太好。在负 xy 平面上绘制它们怎么样?
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=2,
declare function={f(\x,\y)=ifthenelse(\x*\y<0,sqrt(-\x*\y),-\x*\x+\y);}]
\begin{axis}[hide axis,
legend pos=outer north east,
view={-145}{45},clip=false
]
\addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
\addlegendentry{$f(x,y)$}
\draw[thick,-stealth] (0,0,0) -- (0,4,0) node[below]{$y$};
\draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
\draw[thick,-stealth] (0,0,0) -- (4,0,0) node[above]{$x$};
\pgfplotsinvokeforeach{0,22.5,...,90}{%
\draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
\end{axis}
\end{tikzpicture}
\end{document}
这是带有勾号的第三个版本。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=2,
declare function={f(\x,\y)=ifthenelse(\x*\y<0,sqrt(-\x*\y),-\x*\x+\y);}]
\begin{axis}[axis on top,xlabel={$x$},ylabel={$y$},
axis lines=middle,xtick={-1,0,1},ytick={-1,0,1},
legend pos=outer north east,
z axis line style={opacity=0},
view={-145}{45},clip=false
]
\addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
\addlegendentry{$f(x,y)$}
\draw[-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
\pgfplotsinvokeforeach{0,22.5,...,90}{%
\draw[-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
\end{axis}
\end{tikzpicture}
\end{document}