Lecture 13: Data Visualization with IPython

Dr. Aijun Zhang - STAT3622 Data Visualization

17 November 2016

1. IPython and Jupyter Notebook

Download and install Python 2.7 (or 3.3+) and Jupyter Notebook through the Anaconda distribution, including Windows, OSX and Linux.

Setting up Jupyter Notebook Public Server on Linux with reference to this link (Optional)


Inserting Images

  1. Use ![title] (image url) IPython

  2. Use HTML/img directly

Inserting YouTube Videos

In [1]:
from IPython.display import YouTubeVideo
# A talk by the IPython's author: Fernando PĂ©rez
YouTubeVideo('F4rFuIb1Ie4', width=500)
Out[1]:

2. Python Graphics

In [2]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import interactive
interactive(True)

y = np.random.randn(300)
plt.plot(y)
Out[2]:
[<matplotlib.lines.Line2D at 0x7f0117ea4090>]
In [3]:
plt.hist(y)
Out[3]:
(array([  2.,   9.,  13.,  28.,  46.,  60.,  63.,  55.,  15.,   9.]),
 array([-3.10314584, -2.57248505, -2.04182426, -1.51116347, -0.98050268,
        -0.44984189,  0.08081891,  0.6114797 ,  1.14214049,  1.67280128,
         2.20346207]),
 <a list of 10 Patch objects>)
In [4]:
plt.boxplot(y)
Out[4]:
{'boxes': [<matplotlib.lines.Line2D at 0x7f0117c76510>],
 'caps': [<matplotlib.lines.Line2D at 0x7f0117c84410>,
  <matplotlib.lines.Line2D at 0x7f0117c84a50>],
 'fliers': [<matplotlib.lines.Line2D at 0x7f0117c91710>],
 'means': [],
 'medians': [<matplotlib.lines.Line2D at 0x7f0117c910d0>],
 'whiskers': [<matplotlib.lines.Line2D at 0x7f0117c766d0>,
  <matplotlib.lines.Line2D at 0x7f0117c76d90>]}
In [5]:
x = np.random.randn(100)
y = x + np.random.randn(100)
plt.scatter(x, y)
Out[5]:
<matplotlib.collections.PathCollection at 0x7f0117bb8810>
In [6]:
x = np.linspace(-10., 10., 1000)
y = np.sin(3 * x) * np.exp(-.1 * x**2)
plt.subplot(121)
plt.plot(x,y)
plt.subplot(122, polar=True)
plt.polar(x, y)
Out[6]:
[<matplotlib.lines.Line2D at 0x7f0117b00fd0>]
In [7]:
plt.imshow(np.random.rand(10, 10), interpolation='none')
Out[7]:
<matplotlib.image.AxesImage at 0x7f01179f3a90>