Plotting
Last updated
Last updated
Plotting in julia can be obtained using a specific plotting package (e.g. Gadfly, Winston) or, as I prefer, use the Plots package that provide a unified API to several supported backends
Backends are chosen running chosenbackend()
(that is, the name of the corresponding backend package, but written all in lower case) before calling the plot
function. You need to install at least one backend before being able to use the Plots
package. My preferred one is PlotlyJS (a julia interface to the plotly.js visualization library. ), but you may be interested also in PyPlot (that use the excellent python matplotlib VERSION 2).
For example:
Attention not to mix using different plotting packages (e.g.Plots
and one of its backends). I had troubles with that. If you have already imported a plot package and you want to use an other package, always restart the julia kernel (this is not necessary, and it is one of the advantage, when switching between different bakends of the Plots
package).
You can find some useful documentation on Plots
backends:
The following example uses StatsPlots in order to work directly on DataFrames (rather than on arrays). Passing the dataFrame as first argument of the @df
macro, you can access its columns by name and split the overall series using a third column.
The first call to plot()
create a new plot. Calling plot!()
modify instead the plot that is passed as first argument (if none, the latest plot is modified)
Use the fill(fillrange,fillalpha,fillcolor)
attribute, e.g. fill = (0, 0.5, :blue)
.
To save the figure just call one of the following:
While an updated, expanded and revised version of this chapter is available in "Chapter 9 - Working with Data" of Antonello Lobianco (2019), "Julia Quick Syntax Reference", Apress, this tutorial remains in active development.