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...