4

I have a simple 2D vector, however the points are aligned such that the vectors at the top pointing upwards are not include in the plot. I was wondering if there's a way to make the vector field more evenly distributed as seen here,enter image description here.

The image is the second axis in the pgfplot.

 \begin{figure}[h]
 \begin{tikzpicture}
 \begin{axis}[
     ticks=none,
    view     = {0}{90},
  domain   = -1:1,
  y domain = -1:1,
  samples  = 21,
  xmax     = 1,
  ymax     = 1
]
\addplot3 [blue, quiver={u={-(x)/(x^2+y^2)}, v={-(y)/(x^2+y^2)}, scale 
arrows=0.04},samples=8,->] (x,y,0);
\draw (axis cs:0,0) node [above] {$z_0$};
\filldraw(axis cs: 0,0)circle(1pt); 

\end{axis}
\begin{axis}[ xshift=8cm,
ticks=none,
  view     = {0}{90},
  domain   = -1:1,
  y domain = -1:1,
  samples  = 21,
  xmax     = 1,
  ymax     = 1
  ]
  \draw (axis cs:1.25,1.25) circle [blue, radius=0.3];
  \addplot3 [blue, quiver={u={(x)/(x^2+y^2)}, v={(y)/(x^2+y^2)}, scale 
   arrows=0.04},samples=8,->] (x,y,0);
\draw (axis cs:0,0) node [above] {$z_0$};
\filldraw(axis cs: 0,0)circle(1pt); 

\end{axis}

\end{tikzpicture}
\caption{Sink and source centred around $z_0$.}

\end{figure}

1 Answer 1

3

The problem comes from xmax and ymax, which clips the overshooting vectors away.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
 \begin{tikzpicture}
 \begin{axis}[
     ticks=none,
    view     = {0}{90},
  domain   = -1:1,
  y domain = -1:1,
  samples  = 21,
%   xmax     = 1,
%   ymax     = 1
]
\addplot3 [blue, quiver={u={-(x)/(x^2+y^2)}, v={-(y)/(x^2+y^2)}, scale 
arrows=0.04},samples=8,->] (x,y,0);
\draw (axis cs:0,0) node [above] {$z_0$};
\filldraw(axis cs: 0,0)circle(1pt); 

\end{axis}
\begin{axis}[ xshift=8cm,
ticks=none,
  view     = {0}{90},
  domain   = -1:1,
  y domain = -1:1,
  samples  = 21,
%   xmax     = 1,
%   ymax     = 1,
  ]
  %\draw (axis cs:1.25,1.25) circle [blue, radius=0.3];

  \addplot3 [blue, quiver={u={(x)/(x^2+y^2)}, v={(y)/(x^2+y^2)}, scale 
   arrows=0.04},samples=8,->] (x,y,0);
\draw (axis cs:0,0) node [above] {$z_0$};
\filldraw(axis cs: 0,0)circle(1pt); 

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

4
  • Yeah I ended up doing something similar to that, thanks for trying its a shame there's not a proper way of 'windowing' the vector field so that they're equally distributed. Commented Jan 16, 2019 at 16:27
  • @JohnMiller Actually I found a much more elegant (IMHO) proposal. The issue is that you specify xmax and ymax, which clips the vectors away. This also explains the asymmetric behavior.
    – user121799
    Commented Jan 16, 2019 at 16:35
  • Oh thank you this is much more elegant, I'm not sure why its in terms of the xmax and ymax. I've never actually understood the difference between the domain and the two so perhaps I should read up on that. Commented Jan 16, 2019 at 19:23
  • @JohnMiller xmax will cut off at x=xmax regardless of the domain. Since you do not specify xmin, the result is asymmetric.
    – user121799
    Commented Jan 16, 2019 at 19:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .