Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
IPython Notebook Essentials

You're reading from   IPython Notebook Essentials Compute scientific data and execute code interactively with NumPy and SciPy

Arrow left icon
Product type Paperback
Published in Nov 2014
Publisher
ISBN-13 9781783988341
Length 190 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Luiz Felipe Martins Luiz Felipe Martins
Author Profile Icon Luiz Felipe Martins
Luiz Felipe Martins
Arrow right icon
View More author details
Toc

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:

IPython magics

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image