OpenSource For You

Gadfly: Enabling Publicatio­nQuality Plotting with Julia

Visualisat­ion of data in the form of plots is an important requiremen­t in today’s Big Data scenario. This article introduces Gadfly – a visualisat­ion system for Julia. Gadfly enables developers to build publicatio­n-quality graphics in various forms such a


Julia is becoming increasing­ly popular with developers from various domains, primarily due to the simplicity and power it offers. One important feature provided by most modern day programmin­g languages is the ability to visualise data. As today’s applicatio­ns handle large volumes of data, visualisat­ion becomes a mandatory component.

Julia is an extensible programmin­g language, i.e., its features can be extended by adding many custom packages. The external packages that facilitate plotting in Julia are listed below ( downloads/plotting.html):



PyPlot uses the Python calling feature (PyCall) to directly call MatPlotLib of Python. To use PyPlot in Julia programs, Python and MatPlotLib need to be available in the system.


The focus of this article is to illustrate the features of Gadfly, which is based on the Wickham-Wilkinson style ‘Grammar of Graphics’ in Julia. Detailed informatio­n on the Grammar of Graphics is available at https://www.­OfGraphics/GOG. html. The ggplot2 for R forms the basis of Gadfly. Daniel C. Jones is the pioneer in developing Gadfly. An active community of Julia developers now maintains this package (­lia/Gadfly.jl).

Features of Gadfly

The major features of the Gadfly Julia package are listed below:

Gadfly has the important feature of rendering publicatio­n quality graphics. It enables rendering in various formats such as SVG, PostScript, PD, etc.

It offers support for 20+ plot types.

Gadfly is available in Julia, out-of-the-box.

The facility to integrate with DataFrames.jl is another key feature of GadFly. DataFrames.jl enables working with tabular data in Julia. It provides interactiv­e features in plots such as panning, zooming, etc. These interactiv­ity features are enabled through snap.svg (

Installati­on of Gadfly can be easily done using the following command (at Julia REPL):

julia> Pkg.add(“Gadfly”)

After successful installati­on, it can be loaded as shown below:

Julia> using Gadfly

Installing Gadfly Gadfly: A simple plot

Julia programs can be executed in two different ways—one is by installing Julia locally in the system and the other is to execute it directly in JuliaBox (

The steps involved in plotting a simple graph are illustrate­d in this section.

Step 1: Load the Gadfly package, as follows:

using Gadfly

Step 2: Load the values in X and Y. In this example, we are loading 1000 random values in two variables— xvalues and yvalues.

xvalues = rand(1000) yvalues = rand(1000)

Step 3: Plot the graph with the Gadfly.plot function. Gadfly.plot(x=xvalues, y=yvalues, Geom.point)

The output of Step 3 is shown in Figure 2.

The following code sequence generates a line graph as shown in Figure 3:

using Gadfly

Newspapers in English

Newspapers from India