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?

  • $\begingroup$ 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). $\endgroup$
    – smh
    Jun 22, 2020 at 20:41
  • 1
    $\begingroup$ 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. $\endgroup$ Jun 22, 2020 at 21:04
  • $\begingroup$ Taking into account @MaximUmansky comment, I suggest that you check this answer: scicomp.stackexchange.com/questions/18760/… $\endgroup$
    – nicoguaro
    Jun 23, 2020 at 0:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.