# Domain coloring¶

In [2]:
%matplotlib inline
from pylab import *
from numpy import *

In [3]:
def Zrange(limits, nsampl=400):
rmin, rmax, imin, imax = limits
rsampl = max(nsampl, (rmax-rmin)/float(imax-imin)*nsampl)
isampl = max(nsampl, (imax-imin)/float(rmax-rmin)*nsampl)
r = linspace(rmin, rmax, rsampl)
i = linspace(imin, imax, rsampl)
R, I = meshgrid(r, i)
return R + 1j*I

In [4]:
X = Zrange([-1, 1, -1, 1])

In [5]:
# http://nbviewer.ipython.org/github/empet/Math/blob/master/DomainColoring.ipynb
figure(figsize=(6,6))

def Z2RGB(X):

# magnitude
V = log(abs(X))
V = (V - floor(V))
RGB=dstack((V, V, V))

# phase
R = ((angle(-X)/(2*pi)+.5)*2).clip(0,1)
G = ((angle(-X)/(2*pi))*2).clip(0,1)
B = zeros_like(R, float)
RGB3 = dstack((R, G, B))

# hard light blending
I = RGB3 < 0.5
RGB4 = 1-(1-2*(RGB3-0.5))*(1-RGB)
RGB4[I] = 2*RGB3[I]*RGB[I]
return RGB4

def Cplot(func, zlimits, nsampl = 400):
X = Zrange(zlimits, nsampl)
imshow(Z2RGB(func(X)), origin="lower", extent = zlimits)

limits = [-2, 2, -2, 2]
Cplot(lambda X: X, limits)

In [6]:
figure(figsize=(10, 5))
func = lambda X: sin(X)
Cplot(func, [-8, 8, -4, 4])

In [7]:
figure(figsize=(10, 5))
func = lambda X: -(1+X)/(1-X)
Cplot(func, [-4, 4, -2, 2])

In [8]:
figure(figsize=(10, 5))
func = lambda X: (X+2)**2 * (X-1-2j) * (X+1j)
Cplot(func, [-5, 4, -2, 1.7])

In [ ]: