Running a web notebook

The newest release of IPython introduced a new exciting feature – the web notebook. A so called "notebook server" can serve notebooks over the web. We can now start a notebook server and have a web-based IPython environment. This environment has most of the features in the regular IPython environment. The new features include the following:

  • Displaying images and inline plots
  • Using HTML and Markdown in text cells
  • Importing and exporting of notebooks

Getting ready

Before we start, we should make sure that all the required software is installed. There is a dependency on tornado and zmq. See the Installing IPython recipe in this chapter for more information.

How to do it...

  • Running a notebook: We can start a notebook with the following code:
    $ ipython notebook
    
    [NotebookApp] Using existing profile dir: u'/Users/ivanidris/.ipython/profile_default'
    [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888
    [NotebookApp] Use Control-C to stop this server and shut down all kernels.
    

    As you can see, we are using the default profile. A server started on the local machine at port 8888. We will learn how to configure these settings later on in this chapter. The notebook is opened in your default browser; this is configurable as well:

    How to do it...

    IPython lists all the notebooks in the directory where you started the notebook. In this example no notebooks were found. The server can be stopped with Ctrl + C.

  • Running a notebook in the pylab mode: Run a web notebook in the pylab mode with the following command:
    $ ipython notebook --pylab
    

    This loads the Scipy, NumPy, and Matplotlib modules.

  • Running notebook with inline figures: We can display inline Matplotlib plots with the inline directive, using the following command:
    $ ipython notebook --pylab inline
    
  1. Create a notebook: Click on the New Notebook button to create a new notebook:
    How to do it...
  2. Create an array: Create an array with the arange function. Type the command in the following screenshot, and press Enter:
    How to do it...

    Next, enter the following command and press Enter. You will see the output as shown in Out [2] in the following screenshot:

    How to do it...
  3. Plot the sinc function: Apply the sinc function to the array and plot the result, as shown in the following screenshot:
    How to do it...

How it works...

The inline option lets you display inline Matplotlib plots. When combined with the pylab mode, you don't need to import the NumPy, SciPy, and Matplotlib packages.

See also

The Installing IPython recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset