我正在尝试生成斜率场 dy/dx = (x-1)*(y+2)/3,以说明沿 x=1 和 y=-2 线,解曲线的斜率为零,由水平线元素表示。但是,用于生成箭头的点似乎不是沿这些线的点,因此线元素看起来不是水平的。我如何调整设置以确保采样点使用 x=1 和 y=-2?
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
Consider the following slope field. \par\bigskip
\begin{center}
\def\length{sqrt(1+((x-1)*(y+2)/3)^2)}
\begin{tikzpicture}[>=stealth,x=1.5cm,y=1.5cm,scale=1.85,font=\footnotesize]
\begin{axis}[
axis lines=middle,
view={0}{90},
domain=-3:3,
xmin=-3.5,
xmax=3.5,
ymin=-3.5,
ymax=3.5,
samples=18,
axis equal image,
ticklabel style = {font=\tiny},
xtick={-3,-2,...,3},
ytick={-3,-2,...,3}
]
\addplot3 [lightgray, quiver={u={1/(\length)}, v={((x-1)*(y+2)/3)/(\length)}, scale arrows=0.2, every arrow/.append style={-stealth}}] (x,y,0);
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案1
我认为问题在于您添加了一个samples
键。如果您对其进行注释,它应该可以正常工作。为了以防万一,我使用samples at
键强制 X 具有 -1 的值。
以防我误解了你想要什么,生成的图像如下,其中 x=1 处有“线性”箭头。对吗?
MWE 表示:
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
Consider the following slope field. \par\bigskip
\begin{center}
\def\length{sqrt(1+((x-1)*(y+2)/3)^2)}
\begin{tikzpicture}[>=stealth,x=1.5cm,y=1.5cm,scale=1.85,font=\footnotesize]
\begin{axis}[
axis lines=middle,
view={0}{90},
domain=-3:3,
samples at={-3,-2.5,...,3}, <--- (!)
xmin=-3.5,
xmax=3.5,
ymin=-3.5,
ymax=3.5,
%samples=18,
axis equal image,
ticklabel style = {font=\tiny},
xtick={-3,-2,...,3},
ytick={-3,-2,...,3}
]
\addplot3 [lightgray, quiver={u={1/(\length)}, v={((x-1)*(y+2)/3)/(\length)}, scale arrows=0.2, every arrow/.append style={-stealth}}] (x,y,0);
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}