考虑以下具有奇点的颤动图:
如果长度大于给定的阈值,有没有办法省略箭头?
并不是说我没有要求颜色图或类似的东西。
\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-2,xmax=2,ymin=-2,ymax=2,view={0}{90},xlabel=\empty,xlabel=\empty]
\addplot3+ [samples=15,->,black,%restrict u to domain=0:10,
quiver={
u={x/(x^2 + y^2)},
v={y/(x^2 + y^2)},
scale arrows=0.3,
},
] {0};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您只需添加一个过滤器即可。
\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-2,xmax=2,ymin=-2,ymax=2,view={0}{90},xlabel=\empty,xlabel=\empty]
\addplot3+ [samples=15,->,black,%restrict u to domain=0:10,
quiver={
u={x/(x^2 + y^2)},
v={y/(x^2 + y^2)},
scale arrows=0.3,
},
x filter/.expression={x*x+y*y<0.2? nan:x},
] {0};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
我无法运行你的代码,但是使用这个答案我可能已经接近解决方案了。奇点位于 x=y=0,您可以通过x^2+y^2
用替换 来手动将其切掉max(x^2+y^2,0.5)
。
\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
% from https://tex.stackexchange.com/a/34010/121799
\def\length{max(x^2+y^2,0.5)}
\begin{tikzpicture}
\begin{axis}[domain=-2:2, view={0}{90}]
\addplot3[blue, quiver={u={x/(\length)}, v={y/(\length)}, scale arrows=0.3}, -stealth,samples=20] {0};
\end{axis}
\end{tikzpicture}
\end{document}
还要注意,如果切换到极坐标,可能会得到更好的结果,其中u=cos(phi)/r
和v=sin(phi)/r
。
答案3
人们可以侵入pgfplots
箭筒处理程序并规范化该向量。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\makeatletter
\def\pgfplotsplothandlersurveypoint@quiver{%
% the arrow components are computed here
\pgfplots@quiver@prepare@u
\pgfplots@quiver@prepare@v
\pgfplotsifcurplotthreedim{% 3d?
\pgfplots@quiver@prepare@w
}{%
\let\pgfplots@quiver@w=\pgfutil@empty
}%
%%% we add our code that checks arrow length
\pgfmathsetmacro\vecnormsq{\pgfplots@quiver@u*\pgfplots@quiver@u+\pgfplots@quiver@v*\pgfplots@quiver@v}
\pgfmathsetmacro\vecnorm{sqrt(\vecnormsq)}
\pgfmathsetmacro\normmax{1}
% rescale if necessary
\pgfmathparse{\vecnormsq > \normmax}
\ifpgfmathfloatcomparison
\message{too long!!}
\pgfmathsetmacro\pgfplots@quiver@u{\pgfplots@quiver@u/\vecnorm*\normmax}
\pgfmathsetmacro\pgfplots@quiver@v{\pgfplots@quiver@v/\vecnorm*\normmax}
\fi
%%% end of our addendum
\pgfplotsaxisparsecoordinate % nonsense
\pgfplotsaxispreparecoordinate % nonsense
\ifpgfplotsaxisparsecoordinateok
% update limit ≈ update the bounding box
\pgfplotsaxisupdatelimitsforcoordinate\pgfplots@current@point@x\pgfplots@current@point@y\pgfplots@current@point@z
% the arrow are being shifted; too late to rescale
\pgfmathadd@{\pgfplots@quiver@u}{\pgfplots@current@point@x}%
\let\pgfplots@quiver@u=\pgfmathresult
\pgfmathadd@{\pgfplots@quiver@v}{\pgfplots@current@point@y}%
\let\pgfplots@quiver@v=\pgfmathresult
\pgfplotsifcurplotthreedim{% 3d?
\pgfmathadd@{\pgfplots@quiver@w}{\pgfplots@current@point@z}%
\let\pgfplots@quiver@w=\pgfmathresult
}{}%
% update limit ≈ update the bounding box
\ifpgfplots@quiver@updatelimits
\pgfplotsaxisupdatelimitsforcoordinate\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w
\fi
\fi
\pgfplotsaxisdatapointsurveyed % nonsense
}%
\begin{tikzpicture}
\begin{axis}[,view={0}{90}]
\addplot3+[samples=15,->,black,%restrict u to domain=0:10,
quiver={
u={ 2*y / (x^2+y^2)},
v={ -2*x / (x^2+y^2)},
scale arrows=1,
},
]{0};
\end{axis}
\end{tikzpicture}
\end{document}