<jupyter_start><jupyter_text>Hertzian Dipole<jupyter_code># Make xyz axes
axes_len_min, axes_len_max = -1.2,1.2
xx,xy,xz = np.array([axes_len_min, axes_len_max]),np.array([0.0,0.0]),np.array([0.0,0.0])
yx,yy,yz = np.array([0.0,0.0]),np.array([axes_len_min, axes_len_max]),np.array([0.0,0.0])
zx,zy,zz = np.array([0.0,0.0]),np.array([0.0,0.0]),np.array([axes_len_min, axes_len_max])
axis_x = mlab.plot3d(xx,xy,xz)
axis_y = mlab.plot3d(yx,yy,yz)
axis_z = mlab.plot3d(zx,zy,zz)
mlab.text3d(axes_len_max+0.2, -0.05, -0.05, 'x', scale=0.25)
mlab.text3d(0.0, axes_len_max+0.2, 0.0, 'y', scale=0.25)
mlab.text3d(0.0, 0.0, axes_len_max+0.2, 'z', scale=0.25)

# Make Hertzian dipole radiation pattern mesh & display
# from http://stackoverflow.com/questions/20668818/python-3d-plotting-of-measurement-data
def r(phi,theta):
    r = np.sin(phi)**2
    return r

phi, theta = np.mgrid[1e-2:2*np.pi-1e-2:201j, 1e-4:np.pi:101j]

x = r(phi,theta)*np.sin(phi)*np.cos(theta)
y = r(phi,theta)*np.sin(phi)*np.sin(theta)
z = r(phi,theta)*np.cos(phi)

intensity0 = r(phi,theta) #colorize surface to show radiation pattern amplitude

obj = mlab.mesh(x, y, z, scalars=intensity0, representation='surface', opacity=1.0)
mlab.show()<jupyter_output><empty_output><jupyter_text>More directional antenna pattern with sidelobes<jupyter_code># Make xyz axes
axes_len_min, axes_len_max = -1.2,1.2
xx,xy,xz = np.array([axes_len_min, axes_len_max]),np.array([0.0,0.0]),np.array([0.0,0.0])
yx,yy,yz = np.array([0.0,0.0]),np.array([axes_len_min, axes_len_max]),np.array([0.0,0.0])
zx,zy,zz = np.array([0.0,0.0]),np.array([0.0,0.0]),np.array([axes_len_min, axes_len_max])
axis_x = mlab.plot3d(xx,xy,xz)
axis_y = mlab.plot3d(yx,yy,yz)
axis_z = mlab.plot3d(zx,zy,zz)
mlab.text3d(axes_len_max+0.2, -0.05, -0.05, 'x', scale=0.25)
mlab.text3d(0.0, axes_len_max+0.2, 0.0, 'y', scale=0.25)
mlab.text3d(0.0, 0.0, axes_len_max+0.2, 'z', scale=0.25)

def r(phi,theta):
    r = np.sin(phi)**4 * np.cos(2*theta)**2 * np.abs(np.cos(3*theta))
    return r

phi, theta = np.mgrid[1e-2:2*np.pi-1e-2:201j, 1e-4:np.pi:101j]

x = r(phi,theta)*np.sin(phi)*np.cos(theta)
y = r(phi,theta)*np.sin(phi)*np.sin(theta)
z = r(phi,theta)*np.cos(phi)

intensity0 = r(phi,theta)

obj = mlab.mesh(x, y, z, scalars=intensity0, representation='surface', opacity=1.0)#, colormap='jet')
mlab.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup