我正在尝试使用以下代码绘制矢量场和圆。按照原样使用代码,蓝色圆圈看起来偏离中心。如果我注释掉该绘制命令并取消注释另一个命令,蓝色圆圈根本就不会绘制。为什么会发生这种情况?如何修复?我觉得我错过了一些非常简单的东西。
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\def\length{sqrt(1+(x+y)^2)}
\begin{tikzpicture}[>=latex,x=1.5cm,y=1.5cm,scale=1.85,font=\footnotesize]
\begin{axis}[
axis lines=middle,
view={0}{90},
domain=-2.5:2.5,
samples=18,
axis equal image,
ticklabel style = {font=\tiny}
]
\addplot3[
gray,
quiver={u={1/(\length)},
v={(x+y)/(\length)},
scale arrows=0.2,
every arrow/.append style={-latex}}
] (x,y,0);
% \draw (axis cs:0,0) circle [blue, radius=1];
\end{axis}
\draw[thick,blue] (0,0) circle (1);
\end{tikzpicture}
\end{document}
答案1
添加以使环境\pgfplotsset{compat=newest}
内的坐标系与宏(以及和类似宏)同步。这样,您可以省略:axis
\path
\draw
\fill
axis cs
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[>=latex, x=1.5cm, y=1.5cm, scale=1.85, font=\footnotesize]
\def\length{sqrt(1+(x+y)^2)}
\begin{axis}[
axis lines=middle,
view={0}{90},
domain=-2.5:2.5,
samples=18,
axis equal image,
ticklabel style={font=\tiny}
]
\addplot3[
gray,
quiver={u={1/(\length)},
v={(x+y)/(\length)},
scale arrows=0.2,
every arrow/.append style={-latex}},
] (x,y,0);
\draw[blue] (0,0) circle[radius=1];
\end{axis}
\end{tikzpicture}
\end{document}