0-vectors in a vector field

tikz-arrows

I'm trying to plot a vector field with 5 by 5 arrows (25 in total). It looks good, expect for the fact that it arbitrarily chooses "up" as the direction of the 0-vector. How can I tell it to not display 0-length arrows at all?

My code:

\documentclass{article}
\tikzset{>=stealth} 
\usepackage{tikz}
\usepackage{pgfplots} 
\begin{document}
\begin{tikzpicture}

\draw[->, thick] (-3,0)--(3,0) node[right] {$x$};
\draw[->, thick] (0,-3)--(0,3) node[above] {$y$};

\def\factor{0.15}
\foreach \x in {-2.5,-2,...,2.5} {
    \foreach \y in {-2.5,-2,...,2.5}{
            \draw[->] (\x,\y)--++(\factor*\y,-\factor*\x);
    }
}
\end{tikzpicture}
\end{document}

Result (note the arrow tip at the origin):

enter image description here

Best Answer

One possibility with \ifthenelse:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots} 
\usepackage{ifthen}
\tikzset{>=stealth} 
\begin{document}
\begin{tikzpicture}

\draw[->, thick] (-3,0)--(3,0) node[right] {$x$};
\draw[->, thick] (0,-3)--(0,3) node[above] {$y$};

\def\factor{0.15}
\foreach \x in {-2.5,-2,...,2.5} {
    \foreach \y [evaluate=\y as \r using int(ceil(abs(\x)+abs(\y)))] in {-2.5,-2,...,2.5}{
            \ifthenelse{\r=0}{}{\draw[->] (\x,\y)--++(\factor*\y,-\factor*\x);}
    }
}
\end{tikzpicture}
\end{document}

enter image description here

Related Question