contourf

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 or bands

  • an AbstractVector{<:Real} that lists n consecutive edges from low to high, which result in n-1 levels or bands

You can also set the mode attribute to :relative . In this mode you specify edges by the fraction between minimum and maximum value of zs . This can be used for example to draw bands for the upper 90% while excluding the lower 10% with levels = 0.1:0.1:1.0, mode = :relative .

In :normal mode, if you want to show a band from -Inf to the low edge, set extendlow to :auto for the same color as the first level, or specify a different color (default nothing means no extended band) If you want to show a band from the high edge to Inf , set extendhigh to :auto for the same color as the last level, or specify a different color (default nothing means no extended band)

Attributes

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

  colormap     :viridis
  extendhigh   "nothing"
  extendlow    "nothing"
  inspectable  true
  levels       10
  mode         :normal              
using CairoMakie

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

f = Figure()
Axis(f[1, 1])

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

Colorbar(f[1, 2], co)

f          

using CairoMakie

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

f = Figure()
Axis(f[1, 1])

co = contourf!(xs, ys, zs, levels = -0.75:0.25:0.5,
    extendlow = :cyan, extendhigh = :magenta)

Colorbar(f[1, 2], co)

f          

using CairoMakie

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

f = Figure()
Axis(f[1, 1])

co = contourf!(xs, ys, zs,
    levels = -0.75:0.25:0.5,
    extendlow = :auto, extendhigh = :auto)

Colorbar(f[1, 2], co)

f          

Relative mode

Sometimes it's beneficial to drop one part of the range of values, usually towards the outer boundary. Rather than specifying the levels to include manually, you can set the mode attribute to :relative and specify the levels from 0 to 1, relative to the current minimum and maximum value.

using CairoMakie


using Makie.KernelDensity

k = kde([randn() + rand([0, 5]) for i in 1:10000, j in 1:2])

f = Figure(resolution = (800, 500))

Axis(f[1, 1], title = "Relative mode, drop lowest 10%")
contourf!(k, levels = 0.1:0.1:1, mode = :relative)

Axis(f[1, 2], title = "Normal mode")
contourf!(k, levels = 10)

f