# Plotting a Magnetic Field in Spherical Coordinates in Python

I am modeling a Helmholtz Coil as two dipoles from far away and I want to plot the magnetic field.

$$\mathbf{B}(\mathbf{r}) = \frac{\mu_0 |\mathbf{m}|}{4\pi r^3}\left(2\cos\theta\,\hat{\mathbf{r}} + \sin\theta\,\hat{\boldsymbol{\theta}}\right)\, .$$

I am struggling to plot the magnetic field in spherical coordinates in Python. Can somebody show me an easy way to plot 3D functions in spherical coordinates?

• Since your function is of the form $f(\theta,\phi)/r^3$, you could simply plot $f(\theta,\phi)$ using a colormap, either on the surface of a sphere embedded in 3d space or in an unwrapped 2D plot (think MATLAB's imagesc command). – smh Jun 22 '20 at 20:41
• The configuration of a Helmholtz coil is axisymmetric, jut plot the field in 2D and show the axis of symmetry. Something like this hyperphysics.phy-astr.gsu.edu/hbase/magnetic/helmholtz.html but with point dipoles. – Maxim Umansky Jun 22 '20 at 21:04
• Taking into account @MaximUmansky comment, I suggest that you check this answer: scicomp.stackexchange.com/questions/18760/… – nicoguaro Jun 23 '20 at 0:35