# Quiver plot with polar sample points

How can I change the following plot that the sample points are in a polar coordinate system, i.e. on equidistant concentric circles instead in a cartesian grid?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
domain=-10:10,
samples=20,
xmin=-10,xmax=10,
ymin=-10,ymax=10,
zmin=-20,zmax=20,
point meta=z,
height=20cm,
width=15cm,
view={45}{45}
]
\pgfplotsinvokeforeach{-20,0,20}{
\begin{scope}
\clip plot[smooth cycle,variable=\t,domain=0:355] ({7*cos(\t)},{7*sin(\t)},#1);
quiver={
u={-y/(x^2+y^2)},
v={x/(x^2+y^2)},
w={0},
scale arrows=10,
colored=mapped color
},
]
(x,y,#1);
\end{scope}
}
\draw[ultra thick] (0,0,-20) -- (0,0,20);
%
\end{axis}
\end{tikzpicture}
\end{document}


• I do not think that there is a simple switch that you can apply to a quiver plot that makes the arrows follow arcs. Apart from nonlinear transformations, which may be hard to marry to pgfplots, you could just draw these arcs in loops (and use some mapped color, if needed).
– user194703
Mar 27, 2020 at 23:20

This is not a serious answer. All I wanted to do is to find out if one can hack the quiver. It seems to be possible to some extent.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
}
\begin{document}
\makeatletter
\pgfplotsset{quiver/tikz to/.code={\def\pgfplotsplothandlerquiver@vis@path##1{%
%\pgfpathmoveto{##1}%
\pgfplotsaxisvisphasetransformcoordinate\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w
\pgfplotsifcurplotthreedim{%
\pgfcoordinate{quiver@from}{\pgfplotsqpointxyz\pgfplots@current@point@x\pgfplots@current@point@y\pgfplots@current@point@z}%
}{%
\pgfcoordinate{quiver@from}{\pgfplotsqpointxy\pgfplots@current@point@x\pgfplots@current@point@y}%
}%
\pgfplotsifcurplotthreedim{%
\pgfcoordinate{quiver@target}{\pgfplotsqpointxyz\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w}%
}{%
\pgfcoordinate{quiver@target}{\pgfplotsqpointxy\pgfplots@quiver@u\pgfplots@quiver@v}%
}%
\pgfpathmoveto{\pgfpointanchor{quiver@from}{center}}%
\tikzset{insert path={(quiver@from) to
(quiver@target)}}%
}}}%

\makeatother

\begin{tikzpicture}
\begin{axis}[
domain=-10:10,
samples=20,
xmin=-10,xmax=10,
ymin=-10,ymax=10,
zmin=-20,zmax=20,
point meta=z,
height=20cm,
width=15cm,
view={45}{45}
]
\pgfplotsinvokeforeach{-20,0,20}{
\begin{scope}
%\clip plot[smooth cycle,variable=\t,domain=0:355] ({7*cos(\t)},{7*sin(\t)},#1);
quiver={every arrow/.append style={every to/.style={bend right=15}},
u={-y/(x^2+y^2)},
v={x/(x^2+y^2)},
w={0},
scale arrows=10,
colored=mapped color,
tikz to
},
x filter/.expression={x*x+y*y<9 || x*x+y*y > 49 ? nan:x},
]
(x,y,#1);
\end{scope}
}
\draw[ultra thick] (0,0,-20) -- (0,0,20);
%
\end{axis}
\end{tikzpicture}
\end{document}


This does not mean one cannot get the result you have in mind. It might just mean that other approaches may be easier. For instance,

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{3d,arrows.meta,bending}
\pgfplotsset{
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-10:10,
samples=20,
xmin=-10,xmax=10,
ymin=-10,ymax=10,
zmin=-20,zmax=20,
point meta=z,
height=20cm,
width=15cm,
view={45}{45}
]
\pgfplotsinvokeforeach{-20,0,20}{\begin{scope}[canvas is xy plane at z=#1]
\foreach \X in {3,...,7}
{\foreach \Y in {1,...,20}
{\edef\temp{\noexpand\draw[semithick,-{Stealth[bend]},
color of colormap=500+25*#1]
\temp}}
\end{scope}}
\draw[ultra thick] (0,0,-20) -- (0,0,20);
%
\end{axis}
\end{tikzpicture}
\end{document}


Here is the idea of @Schrödinger's cat adapted to the vector field of the original post together with some modifications

• I didn't wanted the arrows to bend
• The grid density increases with increasing radius
• Changed names of polar variables for better reading
• Some minor cosmetic changes
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{3d,arrows.meta,bending}
\pgfplotsset{
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-10:10,
samples=20,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
zmin=-26,zmax=26,
point meta=z,
height=20cm,
width=15cm,
view={45}{30},
%axis lines=none
]
\pgfplotsinvokeforeach{-20,0,20}{\begin{scope}[canvas is xy plane at z=#1]
\foreach \PHI in {1,...,4}{
\foreach \R in {0,50/\PHI,...,349}{
\edef\temp{\noexpand\draw[very thick,-{Stealth[scale=0.5]},opacity=0.5,
color of colormap=500+25*#1]
(\R:\PHI) -- ++({1*sin(\R)/\PHI},{-1*cos(\R)/\PHI});
}
\temp}
}
\end{scope}

\foreach \PHI in {1,...,4}{
\edef\temp{\noexpand\draw[dotted,opacity=0.5,
color of colormap=500+25*#1]
(0,0,#1) circle (\PHI);
}
\temp
}

}
\draw[ultra thick] (0,0,-40) -- (0,0,40);
%
\end{axis}
\end{tikzpicture}
\end{document}


Output: