I'm trying to plot (B_x,B_z) field line an the code is written below. The function I used is 'streamplot(x,z,Bx,Bz)'. After the running, 'x','z','Bx',and 'Bz' have a type as a float64 and the size were (30L,30L), equal.
However, orange canvas plot of the range (0,1) and "ValueError: The rows of 'x' must be equal" are shown after the running. What is the problem in the code?
import numpy as np
import math as m
from matplotlib.pyplot import cm # color map
import matplotlib.pyplot as plt
r_E=6.4*10**6 # (m)
B0=0.0001
Earth = plt.Circle((0, 0), 6400000,color='orange')
plot=plt.figure()
x,z=np.mgrid[-9000000:9000000:30j, -9000000:9000000:30j]
r=np.sqrt(np.add(np.square(x),np.square(z)))
ax=plot.gca()
ax.add_patch(Earth)
B_x=[]
B_z=[]
for i in range(len(x)):
bx=[]
bz=[]
for j in range(len(x)):
bx.append(B0*(r_E/r[i,j])**3*(x[i,j]*z[i,j]/r[i,j]**2)*(1-( 3+x[i,j]/(x[i,j]**2)**(1.0/2) )/8))
bz.append(B0*(r_E/r[i,j])**3/r[i,j]**2*(z[i,j]**2-(x[i,j]**2)*(3+x[i,j]/(x[i,j]**2)**(1.0/2))/8))
B_x.append(bx)
B_z.append(bz)
Bx=np.asarray(B_x)
Bz=np.asarray(B_z)
ax.streamplot(x,z,Bx,Bz)
plt.show(plot)
streamplot
needs x
and z
to be vectors. Try:
x = np.linspace(-90000000,9000000, 30)
z = np.linspace(-90000000,9000000, 30)
ax.streamplot(x,z,Bx,Bz)