Gaston is a plotting package for Julia that relies on gnuplot. It focuses on fast, simple plotting, and leaves publication-quality plots to tools such as pgfplots. This tutorial covers Gaston version 0.7.2.
Gaston's code repository is here.
Make sure that gnuplot is installed on your system and in the system path. Confirm by running in Julia:
gnuplot 5.2 patchlevel 2
Any errors here mean that gnuplot is not properly installed.
Once gnuplot is functional, install Gaston using Julia's package manager by running
Gaston offers four types of plots: regular 2D plots, surface (3D) plots, histograms, and images. Start by loading it into your Julia session:
t = 0:0.01:1 plot(t, sin.(2π*5*t))
You may control certain properties of the axes, as well as the curve. Axes properties are:
A curve's properties are:
plotstyle(allowed values are given in
linestyle(a string containing a combination of
_and space; empty string plots solid line)
marker(allowed values are given in
These follow GnuPlot's standard syntax, and can be set by setting each property in the
plot command. For example:
plot(t,sin.(2π*5*t),title="A sine wave",xlabel="Time (s)",ylabel="Amplitude",grid="on",linewidth=3,color="blue", yrange="[-1.1:1.1]",marker="ecircle",plotstyle="linespoints",linestyle="-.-")
Note that, if the
x coordinate is ommited, the indices of
y will be used instead.
Other curves can be added to the same plot by using the
plot!() command. Only curve properties can be used with this command; the axes properties remain unchanged.
Gaston can plot 3D surfaces using the
surf command, which works in two different ways. The first is by giving it explicit
x=[0,1,2,3] y=[0,1,2] Z=[10 10 10; 10 5 10;10 1 10; 10 0 10] surf(x,y,Z,title = "3D: Valley of the Gnu from gnuplot manual")
The second alternative is to pass
y coordinates to a function.
Note that the
surf command takes the same options as
plot, with the addition of the
zrange axes property.
x = y = -15:0.33:15 surf(x,y,(x,y)->sin.(sqrt.(x.*x+y.*y))./sqrt.(x.*x+y.*y),title="Sombrero",plotstyle="pm3d")
The palette can be set with the
palette setting. See gnuplot's documentation for details and valid values.