In this IPython Notebook we illustrate the Klein's j-function, evaluated in Python mpmath
, and plotted with matplotlib
, using different color functions for domain coloring method: the default color function for cplot
in mpmath
(based on HSL color model) or user-defined color functions, such as color_hsv
, color_phase
(phaseplot), and color_cont
(log modulus contour plot).
We list below the color functions to be set in mpmath.cplot
:
In [1]:
import matplotlib.pyplot as plt
from mpmath import *
from colorsys import hsv_to_rgb, hls_to_rgb
In [2]:
plt.rcParams['figure.figsize'] = 6, 6
In [3]:
pi = 3.1415926535898
In [4]:
def hue(z): # hue value corresponding to a complex number
h = (float(arg(z)) + pi) / (2*pi)
return (h + 0.5) % 1.0
In [5]:
def color_hsv (fz):
if isinf(fz):
return (1.0, 1.0, 1.0)
if isnan(fz):
return (0.5, 0.5, 0.5)
h=hue(fz)
m=fabs(fz)
v=(1-1.0/(1+m**2))**0.2#brightness value
return hsv_to_rgb(h, 0.9, v)# s=0.9 is saturation
In [6]:
def color_phase (fz):
if isinf(fz):
return (1, 1, 1)
elif isnan(fz):
return (0.5, 0.5, 0.5)
else:
return hsv_to_rgb(hue(fz), 1, 1)
In [7]:
def PerFract(x, t, m, M):
x=x/t
return m+(M-m)*(x-floor(x))
def color_cont(fz):
if isinf(fz):
return (1, 1, 1)
if isnan(fz):
return (0.5, 0.5, 0.5)
n=12 #n is the number of rays drawn in a cycle
h=hue(fz)
modul=fabs(fz)
Logm=log(modul)
v=PerFract(Logm, 2*pi/n, 0.7, 1)
return hsv_to_rgb(h, 1, v)
Another color function we used to plot the Riemann zeta function is defined in this IPython Notebook.
Now calling the function cplot
:
cplot(lambda q: kleinj(qbar=q), [-1,1], [-1,1],color=color_function, verbose=True,\
points=100000, file='FileName.png')
or
cplot(lambda t: kleinj(tau=t), [-1,2], [0,1.5], color=color_function,verbose=True,\
points=100000, file='ImageName.png')
with color_function replaced by one of the above defined color functions one gets an image of Klein's j-function, like those displayed below.
For each plot the keyword points
in cplot
is set to 100000, except for kleinjCont.png
where points=200000
.
The images displayed below can be downloaded from github.
In [8]:
from IPython.display import Image
In [9]:
Image(filename='Imags/kleinjHLS.png')
Out[9]:
In [10]:
Image(filename='Imags/kleinjHSV.png')
Out[10]:
In [11]:
Image(filename='Imags/kleinjPhase.png')
Out[11]:
In [12]:
Image(filename='Imags/kleinjCont.png')
Out[12]:
In [13]:
Image(filename='Imags/kleinjtauHLS.png')
Out[13]:
In [14]:
Image(filename='Imags/kleinjtauHSV.png')
Out[14]:
In [15]:
Image(filename='Imags/kleinjtauPhase.png')
Out[15]:
In [16]:
Image(filename='Imags/kleinjtauCont.png')
Out[16]:
We posted on Wikipedia similar plots for the following special functions:
In [1]:
from IPython.core.display import HTML
def css_styling():
styles = open("./custom.css", "r").read()
return HTML(styles)
css_styling()
Out[1]: