# Gaston tutorial¶

• explain that plot returns a figure object
• explain delays and how to configure them

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.

## Installation¶

Make sure that gnuplot is installed on your system and in the system path. Confirm by running in Julia:

In [1]:
run(gnuplot --version)

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 Pkg.add("Gaston").

## Overview of main plotting commands¶

Gaston offers four types of plots: regular 2D plots, surface (3D) plots, histograms, and images. Start by loading it into your Julia session:

In [2]:
using Gaston


### 2D plots¶

To plot a vector y against a vector x, use the command plot.

In [3]:
t = 0:0.01:1
plot(t, sin.(2π*5*t))

Out[3]:

You may control certain properties of the axes, as well as the curve. Axes properties are:

• title
• xlabel
• ylabel
• grid (allowed values: "", "on" or "off")
• xrange
• yrange
• box

A curve's properties are:

• plotstyle (allowed values are given in Gaston.supported_2Dplotstyles variable)
• legend
• color
• linewidth
• linestyle (a string containing a combination of -, ., _ and space; empty string plots solid line)
• pointsize
• marker (allowed values are given in Gaston.supported_markers variable)

These follow GnuPlot's standard syntax, and can be set by setting each property in the plot command. For example:

In [4]:
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="-.-")

Out[4]:

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.

In [5]:
plot!(t,cos.(2π*5*t),color="red",linewidth=2)

Out[5]:

### 3D plots¶

Gaston can plot 3D surfaces using the surf command, which works in two different ways. The first is by giving it explicit x, y and z coordinates.

In [6]:
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")

Out[6]:

The second alternative is to pass x, y coordinates to a function.

Note that the surf command takes the same options as plot, with the addition of the zrange axes property.

In [7]:
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")

Out[7]:

The palette can be set with the palette setting. See gnuplot's documentation for details and valid values.

In [8]:
set(palette="gray")
surf(x,y,(x,y)->sin.(sqrt(x.*x+y.*y))./sqrt.(x.*x+y.*y),title="Sombrero",plotstyle="pm3d")

Out[8]: