Introduction

This notebook is used to generate the various graphs in the lectures.


In [2]:
from __future__ import division

from scipy.stats import norm
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter

mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['lines.color'] = 'r'
mpl.rcParams['axes.titlesize'] = 32
mpl.rcParams['axes.labelsize'] = 24
mpl.rcParams['axes.labelsize'] = 24 
mpl.rcParams['xtick.labelsize'] = 16 
mpl.rcParams['ytick.labelsize'] = 16 

%matplotlib inline

def make_3d_plot(x, y, z, xlabel="$z$", ylabel="$f_Z(z)$"):
    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure(figsize=(12, 8))
    ax = fig.add_subplot(111, projection='3d') 
    surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=cm.autumn, linewidth=0, antialiased=False)
    
    ax.set_xlabel("$x$")
    ax.set_ylabel("$y$")
    ax.set_zlabel("$f_{X,Y}(x, y)$")
    
    return plt

In [32]:
x = np.arange(-3, 3, 0.1)
y = np.arange(-3, 3, 0.1)
x, y = np.meshgrid(x, y)
z = 1 / (2 * np.pi) * np.exp(-(x**2 + y**2) / 2)

make_3d_plot(x, y, z)


Out[32]:
<module 'matplotlib.pyplot' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.pyc'>

In [33]:
x = np.arange(0, 1, 0.1)
y = np.arange(0, 1, 0.1)
x, y = np.meshgrid(x, y)
z = 4*x*y# / (2 * np.pi) * np.exp(-(x**2 + y**2) / 2)

make_3d_plot(x, y, z)


Out[33]:
<module 'matplotlib.pyplot' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.pyc'>

In [12]:
x = np.arange(0, 1, 0.1)
y = np.arange(0, 1, 0.1)
x, y = np.meshgrid(x, y)
z = 12 / 11 * (x ** 2 + x * y + y ** 2)

make_3d_plot(x, y, z)


Out[12]:
<module 'matplotlib.pyplot' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.pyc'>

In [13]:
x = np.arange(0, 1, 0.1)
y = np.arange(0, 1, 0.1)
x, y = np.meshgrid(x, y)
z = 4 / 9 * (x * y + x + y + 1)

make_3d_plot(x, y, z)


Out[13]:
<module 'matplotlib.pyplot' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.pyc'>

In [13]:


In [ ]: