In the Wikipedia article on magnetic moments, subsection "Effects on environment" defines the magnetic field H of a magnetic dipole moment. Additionally the magnetic field lines of this field are drawn:
I want to reproduce this picture using Python - Matplotlib. I believe that my result is correct but it is visually poorly represented.
Here is the Python Code that generated the picture above. Does someone know how fix this, so that I get a similar picture as in the wiki article.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x,y = np.meshgrid(np.linspace(-5,5,10),np.linspace(-5,5,10)) # coordinates for the position vector r
m = [0, 1] # magnetic moment of the magnetic dipole moment
mr = m[0] * x + m[1] * y # dot product m * r
r_squared = x**2 + y**2
factor = 1 / ( np.sqrt(r_squared)**5 * 4 * np.pi) # pre factor, that is multiplied with the vector
u = factor * (3 * x * mr - m[0] * r_squared)
v = factor * (3 * y * mr - m[1] * r_squared)
plt.quiver(x,y,u,v)
plt.show()
To do this, on need to define m = (m_x, m_y) = (0, m_y) (as described in the fig description) and compute the dot product r*m = (r_x * m_x + r_y * m_y). Insert this into the formula for H and split the equations into its x and y part (cartesian coordinates).