Find solution for $\Phi(\rho, \theta)$ inside a circular region of radia $a$. The region is enclosed by a circle with the radius $a$, is maintained at potential $−V$ in the upper half circle and at potential $+V$ in the lower half circle as shown in the figure.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
cmap = mpl.colormaps['hot']
import imageio
import os
from scipy.special import legendre
from IPython.display import Image
def Phi(r, theta, V, a):
p1=legendre(1)
p3=legendre(3)
p5=legendre(5)
r=r/a
fx=np.zeros(r.shape)
x=np.cos(theta)
fx= V* ( 3/2*r*p1(x) - 7/8* (r**3)*p3(x) + 11/16*(r**5)*p5(x))
return fx
a=1
Np=50
r1=np.linspace(0,a,2*Np)
theta1=np.linspace(0,np.pi, 2*Np)
[r,theta]=np.meshgrid(r1, theta1)
x=r*np.cos(theta-np.pi/2)
y=r*np.sin(theta-np.pi/2)
x1=r*np.cos(theta+np.pi/2)
y1=r*np.sin(theta+np.pi/2)
pot=Phi(r, theta, 1, a)
plt.pcolor(x,y, pot, vmin=-1.3, vmax=1.3)
plt.pcolor(x1,y1, -pot, vmin=-1.3, vmax=1.3)
plt.gca().set_aspect(1)
#plt.contour(x,y, pot,30, color='w')
plt.xlabel('x-axis')
plt.ylabel('z-axis')
plt.xlim([-1.1, 1.1])
plt.ylim([-1.1, 1.1])
#plt.clim(-1.1,1.1)
plt.title('Potential on x-z plane')
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7ff0372dc850>