Hello. I was wondering how to change the color mapping in the example below. I thought I could change limits in the colorbar and the range of colors in the contour plot would adjust accordingly. Changing the lower limit, for example, does nothing, but update the color bar. Is there a way to make the contour plot and color bar agree?
using CairoMakie
xs = range(-10, 10, 500)
ys = range(-10, 10, 500)
zs = [x * y for x ∈ xs, y ∈ ys]
f = Figure()
ax = Axis(f[1, 1])
contourf!(xs, ys, zs)
Colorbar(f[1,2], limits = (-5000, 50))
f
Generally, the colorbar takes the kind of object to be mapped as its second argument, like so:
using CairoMakie
xs = range(-10, 10, 500)
ys = range(-10, 10, 500)
zs = [x * y for x ∈ xs, y ∈ ys]
f = Figure()
ax = Axis(f[1, 1])
cf = contourf!(xs, ys, zs)
Colorbar(f[1,2], cf)
f
To adjust the limits, it’s usually easier to change the object rather than the colorbar to ensure that the colorbar accurately maps the colors:
xs = range(-10, 10, 500)
ys = range(-10, 10, 500)
zs = [x * y for x ∈ xs, y ∈ ys]
f = Figure()
ax = Axis(f[1, 1])
cf = contourf!(xs, ys, zs; levels = [-5000,-10,0,10,50])
Colorbar(f[1,2], cf)
f