我正在尝试绘制函数的斜率场:(x-y)/(x+y)
。这是我目前得到的结果:
\documentclass{report}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
xmax=1, xmin=0,
ymax=0.6, ymin=-0.6,
domain=0:1,
axis x line=middle,
axis y line=middle,
axis line style={<->},
xlabel={$x$},
ylabel={$y$},
grid style={solid,gray!40},
ticks=none,
]
\addplot3[
gray,
quiver={
u={1},
v={(x-y)/(x+y)},
scale arrows=0.3,
}] (x,y,0);
% \addplot[thick,red,domain=-10:10,samples=1000] {(x-y)/(x+y)};
\end{axis}
\end{tikzpicture}
\end{document}
但它看起来是这样的:
我希望它看起来像这样:
如何绘制包含x
和y
项的函数\addplot
?当您取消注释所提供代码中的行时,它会给出一条错误消息:
! Package pgfplots Error: Sorry, you can't use 'y' in this context. PGFPlots ex
pected to sample a line, not a mesh. Please use the [mesh] option combined with
[samples y>0] and [domain y!=0:0] to indicate a twodimensional input domain.
See the pgfplots package documentation for explanation.
Type H <return> for immediate help.
...
l.28 ...domain=-10:10,samples=1000] {(x-y)/(x+y)};
?
最后,我怎样才能使斜率场中所有线的长度保持恒定,就像上图所示的那样?