# How to make color bar and contour plot agree in makie?

**URL:** <https://discourse.julialang.org/t/how-to-make-color-bar-and-contour-plot-agree-in-makie/136054>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [March 5, 2026, 9:52pm UTC](https://discourse.julialang.org/t/how-to-make-color-bar-and-contour-plot-agree-in-makie/136054 "2026-03-05T21:52:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [March 5, 2026, 9:52pm UTC](https://discourse.julialang.org/t/how-to-make-color-bar-and-contour-plot-agree-in-makie/136054/1 "2026-03-05T21:52:12Z")

</div>

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?

```julia-auto
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

```

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [March 5, 2026, 10:10pm UTC](https://discourse.julialang.org/t/how-to-make-color-bar-and-contour-plot-agree-in-makie/136054/2 "2026-03-05T22:10:36Z")

</div>

Generally, the colorbar takes the kind of object to be mapped as its second argument, like so:

```julia-auto
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:

```julia-auto
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

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [March 6, 2026, 6:32am UTC](https://discourse.julialang.org/t/how-to-make-color-bar-and-contour-plot-agree-in-makie/136054/3 "2026-03-06T06:32:01Z")

</div>

> [@JonasWickman](#):
>
> ```julia-auto
> 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
> 
> ```

Thank you for your explanation!
