Book Image

IPython Notebook Essentials

By : Luiz Felipe Martins
Book Image

IPython Notebook Essentials

By: Luiz Felipe Martins

Overview of this book

Table of Contents (15 chapters)
IPython Notebook Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

IPython magics


Magics are special instructions to the IPython interpreter that perform specialized actions. There are two types of magics:

  • Line-oriented: This type of magics start with a single percent (%) sign

  • Cell-oriented: This type of magics start with double percent (%%) signs

We are already familiar with one of the magic command, that is, %pylab inline. This particular magic does two of the following things: it imports NumPy and matplotlib, and sets up the notebook for inline plots. To see one of the other options, change the cell to %pylab.

Run this cell and then run the cell that produces the plot again. Instead of drawing the graph inline, IPython will now open a new window with the plot as shown in the following screenshot:

This window is interactive and you can resize the graph, move it, and save it to a file from here.

Another useful magic is %timeit, which records the time it takes to run a line of Python code. Run the following code in a new cell in the notebook:

%timeit return_on_investment...