Example: Media in IPython Notebooks

In [1]:
# Import the required modules
import numpy as np
import matplotlib.pyplot as plt
import urllib
# This makes the plots appear inside the notebook
%matplotlib inline 

$1$. Load and display a data file from a URL (i.e. across the web).

In [2]:
url = "http://sam-dolan.staff.shef.ac.uk/mas212/data/quadratic_with_noise.dat"
data = np.loadtxt(urllib.request.urlopen(url))

x, y = data[:,0], data[:,1]

plt.plot(x, y, 's')
plt.xlabel("x")
plt.ylabel("z");

$2$. Load and display an image:

In [3]:
from IPython.display import Image
Image(url="http://sam-dolan.staff.shef.ac.uk/mas212/mandelbrot_frame_29.png")
Out[3]:

$3$. Display a web page (e.g. the Wikipedia page on Python):

In [5]:
from IPython.display import HTML
HTML('<iframe src=http://en.wikipedia.org/wiki/Python_(programming_language) width=800 height=350></iframe>')
Out[5]:

$4$. Import a YouTube video (e.g. from the MAS152 course).

In [7]:
from IPython.display import YouTubeVideo
YouTubeVideo('elFqHzOAlzs')
Out[7]:

$5$. Draw a map of GB & Ireland and add Sheffield. (NB. First need to install the "basemap" package. Under anaconda, try "conda install basemap".)

In [20]:
from mpl_toolkits.basemap import Basemap

## Theselines were added to suppress deprecation warnings ##
import warnings, matplotlib
warnings.filterwarnings("ignore",category=matplotlib.mplDeprecation)

map = Basemap(projection='merc', lat_0=51.5, lon_0=0.0, 
              resolution = 'l', area_thresh = 1000.0, 
              llcrnrlat=50, llcrnrlon=-11.0, 
              urcrnrlat=59, urcrnrlon=2.0)
map.fillcontinents(color='lightgreen')
x,y = map(-1.466944, 53.383611)
map.plot(x, y, 'bo', markersize=4);
In [ ]: