contour

contour(x, y, z)
contour(z::Matrix)

Creates a contour plot of the plane spanning x::Vector, y::Vector, z::Matrix. If only z::Matrix is supplied, the indices of the elements in z will be used as the x and y locations when plotting the contour.

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

To add contour labels, use labels = true, and pass additional label attributes such as labelcolor, labelsize, labelfont or labelformatter.

Attributes

Available attributes and their defaults for Combined{Makie.contour} are:

  alpha           1.0
  color           "nothing"
  colormap        :viridis
  colorrange      MakieCore.Automatic()
  colorscale      identity
  depth_shift     0.0f0
  enable_depth    true
  inspectable     true
  labelcolor      "nothing"
  labelfont       :regular
  labelformatter  Makie.contour_label_formatter
  labels          false
  labelsize       10
  levels          5
  linestyle       "nothing"
  linewidth       1.0
  overdraw        false
  space           :data
  ssao            false
  transparency    false
  visible         true

Examples

using CairoMakie


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

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)

f

Omitting the xs and ys results in the indices of zs being used. We can also set arbitrary contour-levels using levels

using CairoMakie


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

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

contour!(zs,levels=-1:0.1:1)

f

One can also add labels and control label attributes such as labelsize, labelcolor or labelfont.

using CairoMakie


himmelblau(x, y) = (x^2 + y - 11)^2 + (x + y^2 - 7)^2
x = y = range(-6, 6; length=100)
z = himmelblau.(x, y')

levels = 10.0.^range(0.3, 3.5; length=10)
colorscale = ReversibleScale(x -> x^(1 / 10), x -> x^10)
f, ax, ct = contour(x, y, z; labels=true, levels, colormap=:hsv, colorscale)
f