#MonthOfJulia Day 18: Plotting
To start using Gadfly we’ll first need to load the package. To enable generation of PNG, PS, and PDF output we’ll also want the
You can easily generate plots from data vectors or functions.
Gadfly plots are by default rendered onto a new tab in your browser. These plots are mildly interactive: you can zoom and pan across the plot area. You can also save plots directly to files of various formats.
Let’s load up some data from the
nlschools dataset in R’s
MASS package and look at the relationship between language score test and IQ for pupils broken down according to whether or not they are in a mixed-grade class.
Those two examples just scratched the surface. Gadfly can produce histograms, boxplots, ribbon plots, contours and violin plots. There’s detailed documentation with numerous examples on the homepage.
Watch the video below (Daniel Jones at JuliaCon 2014) then read on about Bokeh and Plotly.
The first thing you’ll need to do is install the Bokeh library. If you already have a working Python installation then this is easily done from the command line:
Next load up the package and generate a simple plot.
The plot will be written to a file
bokeh_plot.html in the working directory, which will in turn be opened by the browser. Use
plotfile() to change the name of the file. The plot is interactive, with functionality to pan and zoom as well as resize the plot window.
Plotly package provides a complete interface to plot.ly, an online plotting service with interfaces for Python, R, MATLAB and now Julia. To get an idea of what’s possible with plot.ly, check out their feed. The first step towards making your own awesomeness with be loading the package.
Next you should set up your plot.ly credentials using
Plotly.set_credentials_file(). You only need to do this once because the values will be cached.
Data series are stored in Julia dictionaries.
You can either open the URL provided in the result dictionary or do it programatically:
By making small jumps through similar hoops it’s possible to create some rather intricate visualisations like the 3D scatter plot below. For details of how that was done, check out my code on github.
That was a static version of the plot. However, one of the major perks of Plotly is that the plots are interactive. Plus you can embed them in your site and it will, in turn, benefit from the interactivity. Feel free to interact vigorously with the plot below.
There’s also a fledgling interface to Google Charts. I’m not going to present any code here, but you can find out how to generate a simple interactive plot like the one below on the github page for this series.
[iframe src=”http://188.8.131.52/wp-content/uploads/2015/09/google-chart-scatter.html” width=”750” height=”600” scrolling=”no”]
Obviously plotting and visualisation in Julia are hot topics. Other plotting packages worth checking out are
Gaston. Come back tomorrow when we’ll take a look at using physical units in Julia.