# Plotting Functions

On this page, the basic plotting functions are listed together with examples of their usage and available attributes.

## arrows

AbstractPlotting.arrowsFunction
arrows(points, directions; kwargs...)
arrows(x, y, u, v)
arrows(x::AbstractVector, y::AbstractVector, u::AbstractMatrix, v::AbstractMatrix)
arrows(x, y, z, u, v, w)

Plots arrows at the specified points with the specified components. u and v are interpreted as vector components (u being the x and v being the y), and the vectors are plotted with the tails at x, y.

If x, y, u, v are <: AbstractVector, then each 'row' is plotted as a single vector.

If u, v are <: AbstractMatrix, then x and y are interpreted as specifications for a grid, and u, v are plotted as arrows along the grid.

arrows can also work in three dimensions.

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.arrows,T} where T are:

  arrowcolor   :black
arrowsize    0.3
arrowtail    "nothing"
colormap     :viridis
lengthscale  1.0f0
linecolor    :black
linestyle    "nothing"
linewidth    1
normalize    false
scale        Float32[1.0, 1.0, 1.0]
source

### Examples

using GLMakie
using AbstractPlotting

xs = LinRange(1, 10, 20)
ys = LinRange(1, 15, 20)
us = [cos(x) for x in xs, y in ys]
vs = [sin(y) for x in xs, y in ys]

arrows(xs, ys, us, vs, arrowsize = 0.2, lengthscale = 0.3)

## band

AbstractPlotting.bandFunction

band(x, ylower, yupper; kwargs...) band(lower, upper; kwargs...)

Plots a band from ylower to yupper along x.

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.band,T} where T are:

  ambient         Float32[0.55, 0.55, 0.55]
color           RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.2f0)
colormap        :viridis
colorrange      AbstractPlotting.Automatic()
diffuse         Float32[0.4, 0.4, 0.4]
interpolate     false
lightposition   :eyeposition
linewidth       1
nan_color       RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.0f0)
overdraw        false
shininess       32.0f0
specular        Float32[0.2, 0.2, 0.2]
ssao            false
transparency    false
visible         true
source

### Examples

using GLMakie
using AbstractPlotting

xs = 1:0.2:10
ys_low = -0.2 .* sin.(xs) .- 0.25
ys_high = 0.2 .* sin.(xs) .+ 0.25

scene = band(xs, ys_low, ys_high)
band!(scene, xs, ys_low .- 1, ys_high .-1, color = :red)

## barplot

AbstractPlotting.barplotFunction
barplot(x, y; kwargs...)

Plots a barplot; y defines the height. x and y should be 1 dimensional.

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.barplot,T} where T are:

  color        :black
colormap     :viridis
colorrange   AbstractPlotting.Automatic()
direction    :y
fillto       0.0
marker       GeometryBasics.HyperRectangle
strokecolor  :white
strokewidth  0
visible      true
width        AbstractPlotting.Automatic()
source

### Examples

using GLMakie
using AbstractPlotting

xs = 1:0.2:10
ys = 0.5 .* sin.(xs)

scene = barplot(xs, ys, color = :red, strokecolor = :black, strokewidth = 1)
barplot!(scene, xs, ys .- 1, fillto = -1, color = xs, strokecolor = :black, strokewidth = 1)

## contour

AbstractPlotting.contourFunction

contour(x, y, z)

Creates a contour plot of the plane spanning x::Vector, y::Vector, z::Matrix

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.contour,T} where T are:

  alpha           1.0
ambient         Float32[0.55, 0.55, 0.55]
color           "nothing"
colormap        :viridis
colorrange      AbstractPlotting.Automatic()
diffuse         Float32[0.4, 0.4, 0.4]
fillrange       false
levels          5
lightposition   :eyeposition
linewidth       1.0
nan_color       RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.0f0)
overdraw        false
shininess       32.0f0
specular        Float32[0.2, 0.2, 0.2]
ssao            false
transparency    false
visible         true
source

### Examples

using GLMakie
using AbstractPlotting

xs = LinRange(0, 10, 100)
ys = LinRange(0, 15, 100)
zs = [cos(x) * sin(y) for x in xs, y in ys]

contour(xs, ys, zs)

## contourf

AbstractPlotting.contourfFunction
contourf(xs, ys, zs; kwargs...)

Plots a filled contour of the height information in zs at horizontal grid positions xs and vertical grid positions ys.

The attribute levels can be either

• an Int that produces n equally wide levels
• an AbstractVector{<:Real} that lists consecutive levels
• an AbstractVector{<:Tuple{Real, Real}} that lists levels as (low, high) tuples
• a Tuple{<:AbstractVector{<:Real},<:AbstractVector{<:Real}} that lists levels as a tuple of lows and highs

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.contourf,T} where T are:

  colormap    :viridis
colorrange  AbstractPlotting.Automatic()
levels      10
source
using GLMakie
using AbstractPlotting

xs = LinRange(0, 10, 100)
ys = LinRange(0, 10, 100)
zs = [cos(x) * sin(y) for x in xs, y in ys]

contourf(xs, ys, zs, levels = 10)

## errorbars

AbstractPlotting.errorbarsFunction
errorbars(xs, ys, low, high; kwargs...)
errorbars(xs, ys, lowhigh; kwargs...)
errorbars(points, low, high; kwargs...)
errorbars(points, lowhigh; kwargs...)

Plots errorbars at the given points, extending down low and up by high. Forms with lowhigh use the same error margin downwards and upwards. The direction of the bars can be changed to horizontal by setting the direction attribute to :x.

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.errorbars,T} where T are:

  color         :black
direction     :y
linewidth     1
visible       true
whiskerwidth  10
source

### Examples

using GLMakie
using AbstractPlotting

xs = 0:0.5:10
ys = 0.5 .* sin.(xs)
points = Point2f0.(xs, ys .- 1)
points_2 = Point2f0.(xs, ys .- 2)

lowerrors = fill(0.1, length(xs))
higherrors = LinRange(0.1, 0.5, length(xs))
lowhigherrors = fill(0.2, length(xs))

scene = errorbars(xs, ys, lowerrors, higherrors, color = :red)
errorbars!(scene, points, lowerrors, higherrors, color = LinRange(0, 1, length(xs)))
errorbars!(scene, points_2, lowhigherrors, whiskerwidth = 3, direction = :x)

# plot position scatters so low and high errors can be discriminated
scatter!(scene, xs, ys, markersize = 3, color = :black)
scatter!(scene, points, markersize = 3, color = :black)
scatter!(scene, points_2, markersize = 3, color = :black)

## heatmap

AbstractPlotting.heatmapFunction
heatmap(x, y, values)
heatmap(values)

Plots a heatmap as an image on x, y (defaults to interpretation as dimensions).

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.heatmap,T} where T are:

  ambient         Float32[0.55, 0.55, 0.55]
color           :black
colormap        :viridis
diffuse         Float32[0.4, 0.4, 0.4]
highclip        "nothing"
interpolate     false
levels          1
lightposition   :eyeposition
linewidth       0.0
lowclip         "nothing"
nan_color       RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.0f0)
overdraw        false
shininess       32.0f0
specular        Float32[0.2, 0.2, 0.2]
ssao            false
transparency    false
visible         true
source

### Examples

using GLMakie
using AbstractPlotting

xs = LinRange(0, 10, 100)
ys = LinRange(0, 15, 100)
zs = [cos(x) * sin(y) for x in xs, y in ys]

heatmap(xs, ys, zs)

## image

AbstractPlotting.imageFunction
image(x, y, image)
image(image)

Plots an image on range x, y (defaults to dimensions).

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.image,T} where T are:

  ambient         Float32[0.55, 0.55, 0.55]
color           :black
colormap        Symbol[:black, :white]
diffuse         Float32[0.4, 0.4, 0.4]
highclip        "nothing"
interpolate     true
lightposition   :eyeposition
linewidth       1
lowclip         "nothing"
nan_color       RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.0f0)
overdraw        false
shininess       32.0f0
specular        Float32[0.2, 0.2, 0.2]
ssao            false
transparency    false
visible         true
source

### Examples

using GLMakie
using AbstractPlotting
using FileIO

image(img)

## lines

AbstractPlotting.linesFunction
lines(positions)
lines(x, y)
lines(x, y, z)

Creates a connected line plot for each element in (x, y, z), (x, y) or positions.

Tip

You can separate segments by inserting NaNs.

Attributes

Available attributes and their defaults for Combined{AbstractPlotting.lines,T} where T are:

  ambient         Float32[0.55, 0.55, 0.55]
color           :black
colormap        :viridis
diffuse         Float32[0.4, 0.4, 0.4]
lightposition   :eyeposition
linestyle       "nothing"
linewidth       1.0
nan_color       RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.0f0)
overdraw        false
shininess       32.0f0
specular        Float32[0.2, 0.2, 0.2]
ssao            false
transparency    false
visible         true
source

### Examples

using GLMakie
using AbstractPlotting

xs = 0:0.01:10
ys = 0.5 .* sin.(xs)

scene = lines(xs, ys)
lines!(scene, xs, ys .- 1, linewidth = 5)
lines!(scene, xs, ys .- 2, linewidth = 5, color = ys)
lines!(scene, xs, ys .- 3, linestyle = :dash)