%pylab inline
Populating the interactive namespace from numpy and matplotlib
This general function evaluates the polynomial or rational function $R(z)$ on a fine grid in the complex plane and uses contourf
to plot the region where $|R(z)| \leq 1$:
def plotS(R, axisbox = [-2, 2, -2, 2]):
nptsx = 501
nptsy = 501
xa, xb, ya, yb = axisbox
x = linspace(xa,xb,nptsx)
y = linspace(ya,yb,nptsy)
X,Y = meshgrid(x,y)
Z = X + 1j*Y
Rabs = abs(R(Z))
levels = [-1e9,1,1e9]
Sregion_color = [0.8, 0.8, 1.] # RGB
contourf(X,Y,Rabs,levels,colors=[Sregion_color,'w'])
contour(X,Y,Rabs,[1],colors='k') # boundary
# plot axes
plot([xa, xb], [0, 0], 'k')
plot([0, 0], [ya, yb], 'k')
axis(axisbox)
axis('scaled') # so circles are circular
R = lambda z: 1 + z + 0.5*z**2 + 1./6. * z**3
axisbox = [-4,1,-3,3]
plotS(R, axisbox)
numpy.seterr(all='ignore') # ignore divide by zero errors
R = lambda z: 1./(1.-z)
plotS(R,[-1,3,-2,2])