Basic Julia in Jupyter

In this example, we will use the Iris dataset for some standard analysis. So, start a new Julia Notebook and call it Julia Iris. We can enter a small script to see how the steps progress for a Julia script.

This script uses another package for plotting, which is called Gadfly. You will have to go through similar steps as to the ones we went through in the previous section to install the package before operating the script.

Enter the following script into separate cells of your Notebook:

using RDatasets
using DataFrames
using Gadfly
set_default_plot_size(5inch, 5inch/golden); plot(dataset("datasets","iris"), x="SepalWidth", y="SepalLength", color="Species")

RDatasets is a library that contains several of the commonly used R datasets, such as iris. This is a simple script—we define the libraries that we are going to use, set the size of the plot area, and plot out the iris data points (color coded to Species).

So, you will end up with a starting screen that looks like the following screenshot:

I have used Markdown cells for the text cells. These serve as documentation of the processing and are not interpreted by the engine.

We should take note of a few aspects of the Julia Notebook view:

  • We have the Julia logo (the three colored circles) in the upper-right corner. You will have seen this logo running in other Julia installations (as we saw earlier when we ran the Julia command line previously).
  •  The circle to the right of the Julia logo is a busy indicator. When your script starts, the title of the table says busy as Julia is starting. When your script is running, the circle is filled in black. When it is not running, it is empty.
  •  The rest of the menu items are the same as before.
On my Windows machine, it took quite a while for the Julia Notebook to start for the first time. The Kernel starting, please wait... message was displayed for several minutes.

If you run the script (using the Cell | Run All menu command), your output should look like what's shown in the following screenshot:

The display continues with other statistics about each of the sets, such as PetalWidth and so on.

Note the WARNING message about an incompatibility between sublibraries. Even with the time it took to install and update packages, there were still unresolved issues.

The more interesting part of this is plot of the data points:

I noticed that if you hover the mouse over a graphic, you get grid lines displayed and a slide bar to adjust the zoom level (as shown in the upper-right part of the preceding screenshot).

So, just as if you ran the script in the Julia interpreter, you get your output (with the numerical prefix). Jupyter has counted the statements so that we have incremental numbering of the cells. Jupyter has not done anything special to print out variables.

We started the server, created a new Notebook, and saved it as Julia iris. If we open the IPYNB file on disk (using a text editor), we can see the following:

{ 
  "cells": [ 
    ...<similar to previously displayed> 
  ], 
  "metadata": { 
  "kernelspec": { 
   "display_name": "Julia 0.6.1", 
   "language": "julia", 
   "name": "julia-0.6" 
  }, 
  "language_info": { 
   "file_extension": ".jl", 
   "mimetype": "application/julia", 
   "name": "julia", 
   "version": "0.6.1" 
  } 
 }, 
 "nbformat": 4, 
 "nbformat_minor": 1 
} 
 

This is a little different than what we saw in the previous chapters with other Notebook language coding. Particularly, metadata clearly targets the script cells to be Julia script.

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

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