Example: Media in IPython Notebooks

In [1]:
#  Our first step is to import any required modules.
#  I will use a shortcut to import commonly-used modules in scientific computing:
%pylab inline  

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

In [3]:
import urllib
url = "http://sam-dolan.staff.shef.ac.uk/mas212/data/quadratic_with_noise.dat"
data = np.loadtxt(urllib.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 [4]:
from IPython.display import Image
Image(url="http://sam-dolan.staff.shef.ac.uk/mas212/mandelbrot_frame_29.png")
Out[4]:

\(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=700 height=350></iframe>')
Out[5]:

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

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

\(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 [8]:
from mpl_toolkits.basemap import Basemap
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='grey')
x,y = map(-1.466944, 53.383611)
map.plot(x, y, 'bo', markersize=4);