%matplotlib inline
from pylab import *
from IPython.html.widgets import interact
def f(z, n=100):
f = 0
for i in range(n):
f = f**2 + z
return f
def g(n=1):
print(f(0.34 + 1j * 0.0, n))
interact(g,
n=(0, 100))
(0.34+0j)
<function __main__.g>
num = 200
grid_x = linspace(-1.7, 0.6, num=num)
grid_y = linspace(-1.4, 1.4, num=num)
X, Y = meshgrid(grid_x, grid_y)
Z = X + 1j * Y
data = f(Z)
-c:4: RuntimeWarning: overflow encountered in square -c:4: RuntimeWarning: invalid value encountered in square
extent = (min(grid_x), max(grid_x), min(grid_y), max(grid_y))
imshow(abs(data)**2 < 1000, cmap='gray', extent=extent)
xlabel('real part')
ylabel('imaginary part')
-c:2: RuntimeWarning: invalid value encountered in absolute -c:2: RuntimeWarning: overflow encountered in square
<matplotlib.text.Text at 0x52ae9b0>
imshow(angle(data))
<matplotlib.image.AxesImage at 0x53eb210>
def perfract(x, t, m, M):
x=x/t
return m+(M-m)*(x-np.floor(x))
def domaincol_co(w,s):
H=Hcomplex(w)
m=0.7 # brightness is restricted to [0.7,1]; interval suggested by E Wegert
M=1
n=15 # n=number of isochromatic lines per cycle
isol=perfract(H, 1.0/n, m, M) # isochromatic lines
modul=np.absolute(w)
Logm=np.log(modul)
Logm=np.nan_to_num(Logm)
modc=perfract(Logm, 2*np.pi/n, m, M)# lines of constant log-modulus
V=modc*isol
S = 0.9*np.ones_like(H, float)
HSV = np.dstack((H,S,V))
RGB = hsv_to_rgb(HSV)
return RGB
def plot_domain(color_func, f, re=[-1,1], im= [-1,1], Title='',
s=0.9, N=200, daxis=None):
w=func_vals(f, re, im, N)
domc=color_func(w, s)
plt.xlabel("$\Re(z)$")
plt.ylabel("$\Im(z)$")
plt.title(Title)
if(daxis):
plt.imshow(domc, origin="lower", extent=[re[0], re[1], im[0], im[1]])
else:
plt.imshow(domc, origin="lower")
plt.axis('off')
def func_vals(f, re, im, N): #evaluates the complex function at the nodes of the grid
#re and im are tuples, re=(a,b) and im=(c,d), defining the rectangular region
#N is the number of nodes per unit interval
l=re[1]-re[0]
h=im[1]-im[0]
resL=N*l #horizontal resolution
resH=N*h#vertical resolution
x=np.linspace(re[0], re[1],resL)
y=np.linspace(im[0], im[1], resH)
x,y=np.meshgrid(x,y)
z=x+1j*y
w=f(z)
return w
def Hcomplex(z):# computes the hue corresponding to the complex number z
H=np.angle(z)/(2*np.pi)+1
return np.mod(H,1)
from matplotlib.colors import hsv_to_rgb
plt.rcParams['figure.figsize'] = 8, 5
ab=(-np.pi, np.pi)
cd=(-2,2)
f=lambda z: 1.0/np.tan(z)
plot_domain(domaincol_co, f, re=ab, im=cd, Title='$f(z)=ctan(z)$', N=300, daxis=True)
def plot_domain2(values, color_func, x, y, Title='',
s=0.9, daxis=None):
re=[x.min(),x.max()]
im= [y.min(),y.max()]
w=values.copy()
w[abs(w) > 100] = 0
domc=color_func(w, s)
plt.xlabel("$\Re(z)$")
plt.ylabel("$\Im(z)$")
plt.title(Title)
if(daxis):
plt.imshow(domc, origin="lower", extent=[re[0], re[1], im[0], im[1]])
else:
plt.imshow(domc, origin="lower")
plt.axis('off')
plot_domain2(data, domaincol_co, grid_x, grid_y)
from IPython.html.widgets import interact
interact(lambda param: plot_domain2(data, domaincol_co, grid_x, grid_y, s=param),
param=(0.1, 2, 0.1))
s = "1:33"
s
'1:33'
s.find(':')
1