Plotting

GAIO.jl offers plotting recipes for both Plots.jl and Makie.jl. This means that one can use all the surrounding functionality of Plots.jl or makie.jl, e.g. creating multiple subplots, animations, colorbars, etc. simply by loading either Plots.jl or Makie.jl.

Why offer both Plots and Makie recipes?

Makie.jl offers much more functionality and performance in interactive plots, but suffers much more greatly from the well known time to fist plot problem. Hence GAIO.jl offers Plots.jl recipes for fast, 2-dimensional, non-interactive plotting, and Makie.jl recipes for interactive, 2- and 3-dimensional, or publication-quality visualizations. The following page demonstrates the differences in plotting capability.

Using Plots

To make a plot, one needs to simply load the package. Add Plots using the package manager

pkg> add Plots

Load Plots with

using Plots

Using Makie

To see a plot, one needs to

We will use WGLMakie, which uses WebGL. Add the packages using the package manager

pkg> add WGLMakie

Load the WGLMakie backend with

using WGLMakie
A note on Namespaces

Makie and GAIO.jl both export the type Box. For this reason, it is recommended to also add

const Box = GAIO.Box

to avoid namespace ambiguities.

Common Interface

To plot a BoxSet or BoxMeasure b, simply call

plot(b)

The mutating function plot! is also available. All of Plots.jl's or Makie.jl's keyword arguments, such as color, colormap, etc. can be used. In addition, the keyword argument projection is used to project to a lower dimensional space if the dimension of the space $d$ is greater than 2 for Plots.jl or greater than 3 for Makie.jl. By default, the function used is x -> x[1:2] for Plots.jl and x -> x[1:3] for Makie.jl. For an example using a custom projection function, consider the roots of the function used in Root Covering:

using GAIO
using LinearAlgebra

# domain (-40,40)^n, 3^n roots in domain
g(x) = 100*x + x.^2 - x.^3 .- sum(x)
function Dg(x)  # jacobian
    n = length(x)
    100*I(n) + 2*Diagonal(x) - 3*Diagonal(x.^2) + ones(n,n)
end

dim = 6
center, radius = zeros(dim), 40*ones(dim)
P = BoxPartition(Box(center, radius))

S = cover(P, :)
R = cover_roots(g, Dg, S, steps=dim*5)

We can create a 2-dimensional plot using Plots.jl

using Plots

A = [
    1 0 0 0 0 0;
    0 1 0 0 0 0;
]

p = plot(R, projection = x -> A*x)

2-dimensional plot

We can also make an interactive 3-dimensional plot using Makie.jl. Try panning, zooming with the mouse

using GLMakie

A = [
    1 0 0 0 0 0;
    0 1 0 0 0 0;
    0 0 1 0 0 0;
]

fig, ax, ms = plot(R, projection = x -> A*x)