##// END OF EJS Templates
Proofreading finished up to plotting
David P. Sanders -
Show More
@@ -239,60 +239,77 b' As with Markdown cells, a heading input cell is replaced by a rich text renderin'
239
239
240 Magic commands
240 Magic commands
241 --------------
241 --------------
242 Magic commands, or *magics*, are commands which begin with the symbol ``%``, which send commands to IPython itself (as opposed to standard Python commands which are exported to be run in a Python interpreter).
242 Magic commands, or *magics*, are commands for controlling IPython itself.
243 They all begin with ``%`` and are entered into code input cells. They are entered into standard code cells and executed as usual with :kbd:`Shift-Enter`.
243
244
244 Magics control different elements of the way that the IPython notebook operates. They are entered into standard code cells and executed as usual with :kbd:`Shift-Enter`.
245 There are two types of magics:
245
246
246 There are two types of magics: *line magics*, which begin with a single ``%`` and operate on a single line of the code cell; and *cell magics*, which begin with ``%%`` and operate on the entire contents of the cell.
247 **line magics**:
248 These begin with a single ``%`` and take as arguments the rest of the *same line* of the code cell. Any other lines of the code cell are treated as a standard code cell.
249
250 **cell magics**:
251 These begin with ``%%`` and operate on the *entire* remaining contents of the code cell.
247
252
248 Line magics
253 Line magics
249 ˜˜˜˜˜˜˜˜˜˜˜
254 ˜˜˜˜˜˜˜˜˜˜˜
250 Some of the available line magics are the following:
255 Some of the available line magics are the following:
251
256
252 * ``%load``:
257 * ``%load filename``:
253 Loads a file and places its content into a new code cell.
258 Loads the contents of the file ``filename`` into a new code cell.
259
260 * ``%timeit code``:
261 A simple way to time how long the single line of code ``code`` takes to run
254
262
255 * ``%timeit``:
263 * ``%config``:
256 A simple way to time how long a single line of code takes to run
264 Configuration of the IPython Notebook
257
265
258 * ``%config``:
266 * ``%load_ext``:
259 Configuration of the IPython Notebook
267 Loads an *extension* of the IPython Notebook. Extensions provide extra functionality beyond that of the basic Notebook
260
268
261 * ``%lsmagic``:
269 * ``%lsmagic``:
262 Provides a list of all available magic commands
270 Provides a list of all available magic commands
263
271
264 Cell magics
272 Cell magics
265 ˜˜˜˜˜˜˜˜˜˜˜
273 ˜˜˜˜˜˜˜˜˜˜˜
274 * ``%%latex``:
275 The entire contents of the cell is rendered in LaTeX, as in a Markdown cell but without needing LaTeX delimiters.
266
276
267 * ``%%bash``:
277 * ``%%bash``:
268 Send the contents of the code cell to be executed by ``bash``
278 When the code cell is executed, its contents are sent to be executed by ``bash``.
269
279
270 * ``%%file``:
280 * ``%%file filename``:
271 Writes a file with with contents of the cell. *Caution*: The file is ovewritten without asking.
281 Writes the contents of the cell to the file ``filename``.
282 **Caution**: The file is ovewritten!
272
283
273 * ``%%R``:
284 * ``%%R``:
274 Execute the contents of the cell using the R language.
285 Execute the contents of the cell using the R language.
275
286
276 * ``%%cython``:
287 * ``%%cython``:
277 Execute the contents of the cell using ``Cython``.
288 Execute the contents of the cell using ``Cython``.
278
289
290
291 Several of the cell magics provide functionality to manipulate the filesystem of a remote server to which you otherwise do not have access.
279
292
280
293
281 Plotting
294 Plotting
282 --------
295 --------
283 One major feature of the Notebook is the ability to capture the result of plots as inline output. IPython is designed to work seamlessly together with
296 One major feature of the Notebook is the ability to capture the result of plots as *inline* output, thus displaying the result of running some code right next to the code itself. IPython is designed to work seamlessly with the ``matplotlib`` plotting library to attain this functionality.
284 the ``%matplotlib`` plotting library. In order to set this up, the
285 ``%matplotlib`` magic command must be run before any plotting takes place.
286
297
287 Note that ``%matplotlib`` only sets up IPython to work correctly with ``matplotlib``; it does not actually execute any ``import`` commands and does not add anything to the namespace.
298 To set this up, before any plotting is performed you must execute the
299 ``%matplotlib`` magic command. This performs the necessary behind-the-scenes setup for IPython to work correctly hand in hand with ``matplotlib``; it does
300 *not*, however, actually execute any Python ``import`` commands, that is, no names are added to the namespace.
288
301
289 There is an alternative magic, ``%pylab``, which, in addition, also executes a sequence of standard ``import`` statements required for working with the
302 For more agile *interactive* use of the notebook space, an alternative magic, ``%pylab``, is provided. This does the same work as the ``%matplotlib`` magic, but *in addition* it automatically executes a standard sequence of ``import`` statements required to work with the ``%matplotlib`` library:
290 ``%matplotlib`` library. In particular, it automatically imports all names in the ``numpy`` and ``matplotlib`` packages to the namespace. A less invasive solution is ``%pylab --no-import-all``, which imports just the standard names
303
291 ``np`` for the ``numpy`` module and ``plt`` for the ``matplotlib.pyplot`` module.
304 It will import at the top level `numpy` as `np`, `pyplot` as `plt`, `matplotlib`, `pylab` and `mlab` from `matplotlib`, as well as *all names* from ``numpy`` and ``pylab``. A less invasive, but less interactive, option is ``%pylab --no-import-all``, which does not do these ``import *`` imports.
292
305
293 When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a plotting command is captured in a *separate* window. An alternative is to use::
306 When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a plotting command is captured in a *separate* window. An alternative is to use::
307
294 ``%matplotlib inline``
308 ``%matplotlib inline``
295 which captures the output inline within the notebook format. This has the benefit that the resulting plots will be stored in the notebook document.
309
310 or ``%pylab inline``.
311
312 These capture the output *inline* within the notebook format. This has the benefit that the resulting plots will also stored in the notebook document.
296
313
297
314
298 Converting notebooks to other formats
315 Converting notebooks to other formats
General Comments 0
You need to be logged in to leave comments. Login now