Riemann Zeta Function Visualization

I first heard about Riemann Zeta function when I was watching this video by Numberphile.

The video shows that the sum of natural numbers is equal to -\frac{1}{12}.  (1 + 2 + 3 + 4 + … = - \frac{1}{12} ).

If you’re not familiar with it you might wanna check it online as the result is used in String Theory.

The post here is just a simple visualization of Riemann Zeta function.  I found it interesting because it makes a tornado-like graph.

Riemann zeta function is given by:


Let \zeta(s)=v where s = a + b\imath and v = u + k\imath.

The above plot uses  (x,y,z) coordinates to plot a 3D space where each component is given by:

  • x = Re(v)
  • y = Im(v)
  • z = Im(s)
  • The time component used in the animation is called \theta and it’s given by \theta = Re(s) or simply \theta = a.

To plot the animation I’ve used the following intervals, though the video stops at Re(s) = 3.6:

  • For Re(s): from \left[0.01, 10.0\right), this were calculated at every 0.01 step – shown in the plot at top right;
  • For Im(s): from \left[0.1, 200.0\right), calculated at every 0.1 step – shown as the z axis


The code is given below:

import mpmath
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import gca
from matplotlib.ticker import OldScalarFormatter

def calc_zeta(re, img_name):
    fig = plt.figure()
    axes = Axes3D(fig)
    axes.set_xlabel('X (real)')
    axes.set_ylabel('Y (imag)')
    axes.set_zlabel('Z (Zeta Img)')

    xa, ya, za  = [], [], []

    for i in np.arange(0.1, 200.0, 0.1):
        z = mpmath.zeta(complex(re, i))

    axes.plot(xa, ya, za, label='Zeta Function re(s)=%.3f' % re)

    axes.set_xlim3d(-10.0, 12.0)
    axes.set_ylim3d(-10.0, 12.0)
    axes.set_zlim3d(0.1, 200)

    print "Plot %s !" % img_name

if __name__ == "__main__":
        import psyco
    except ImportError:

    mpl.rcParams['legend.fontsize'] = 10
    file_index = 0
    for i in np.arange(0.01, 10.0, 0.01):
        file_index += 1
        calc_zeta(i, "zeta_plot2_%s.png" % file_index)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s