Example Slide Show

Created directly from an IPython Notebook

Brian Harding

This first slide is only text

Slides can contain:

  • text
  • figures
  • LaTeX code: $A = \pi r^2$
  • anything that the notebook can render!
In [3]:
x = linspace(0,10,100)
y = x**2
plot(x,y,'k')
Out[3]:
[<matplotlib.lines.Line2D at 0x7f21fe3f8310>]

Click on the graph to see the code that generated it. (This feature requires a special template file. By default, the input cell is always shown.)

You can have "slide fragments" which activate when you press the arrow key, such as this image I grabbed from the web:

In [2]:
from IPython.display import Image
Image(url='http://icon.ssl.berkeley.edu/portals/devicon/Images/science/ICON-AT-WORK.png')
Out[2]:

Another neat feature is sub-slides. Try hitting "down"

Sub-slide 1

Sub-slide 2: Even youtube videos work!

In [3]:
from IPython.display import YouTubeVideo
YouTubeVideo('b7RxrFT3cnw', start=15)
Out[3]:

How

This slideshow was created from this IPython notebook.

To make your notebook into a slideshow, first, in the notebook, Choose "Cell Toolbar"-->"Slideshow". Then, modify each cell's "Slide Type" as appropriate (see here for more information, though it's slightly outdated). Don't forget to save the notebook. Then run the following code at the end of the notebook, which:

  1. Calls the command to convert this notebook into HTML slides
  2. Copies the slides to my public_html folder to be served. (Replace this with your own public_html folder)
In [4]:
import subprocess
import shutil
nb_name = 'Slideshow_example.ipynb' # There's probably a way to get this programmatically
cmd = ['ipython', 'nbconvert', '--to', 'slides', nb_name, \
       '--reveal-prefix', '"http://cdn.jsdelivr.net/reveal.js/2.6.2"',\
      '--template','output_toggle']
# The --template command points to a custom template which opens and closes the input code cells with a click
subprocess.call(cmd)
html_name = '%s.slides.html' % (nb_name.split('.')[0])
shutil.copy(html_name, '/home/bhardin2/public_html/slideshows/')
print '(click to reveal code)'
(click to reveal code)

(The "--template output_toggle" option allows you to hide code cells, and reveal them by clicking. If you want to use this, put the output_toggle.tpl file in the same directory as your notebooks.)

After running the above code, view the slideshow by navigating a browser to the file.

The End

Bonus XKCD-style plot

In [14]:
xkcd()
figure(figsize=(5,3))
t = linspace(0,10,100)
y = (10-t)*sin(t)
plot(t,y,'g')
Out[14]:
[<matplotlib.lines.Line2D at 0x7f21fde06d10>]
In [ ]: