# How to add value labels on top of contours in Makie?

**URL:** <https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [April 13, 2021, 11:36pm UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242 "2021-04-13T23:36:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [April 13, 2021, 11:36pm UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/1 "2021-04-13T23:36:53Z")

</div>

The documentation example shows that we can create a contour plot with:

```julia
using CairoMakie

f = Figure(resolution = (800, 600))
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

```

With the result:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/1/419a8f3459436d6b70a8e52e2d190d88b5910802.png)  
However, this example is hard to interpret because there is no way of knowing the value each contour corresponds to. If we add a colorbar it is still not super easy as the continous colorbar confounds the discrete values.  
Is it possible to draw more conventional contours with only one color and with the value labeled on top or next to the contour? (the color thing can be achieved by color=:black  
Random example I found in the web:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1fdde4c657abe8357fcc657e74f5af7e7fca64a.png)

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [April 14, 2021, 7:13am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/2 "2021-04-14T07:13:56Z")

</div>

That would be [https://github.com/JuliaPlots/Makie.jl/issues/832](https://github.com/JuliaPlots/Makie.jl/issues/832) . The PR mentioned in that issue has been merged recently so maybe it could be implemented now?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [April 14, 2021, 10:31am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/3 "2021-04-14T10:31:55Z")

</div>

See [Feature request: contour labels · Issue #832 · JuliaPlots/Makie.jl · GitHub](https://github.com/JuliaPlots/Makie.jl/issues/832#issuecomment-819383094)

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [April 14, 2021, 4:18pm UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/4 "2021-04-14T16:18:10Z")

</div>

Nice, thanks! It still is a workaround but it will work for the meantime.

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [April 1, 2023, 6:24pm UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/5 "2023-04-01T18:24:28Z")

</div>

To have it documented here for posterity:

[This amazing PR](https://github.com/MakieOrg/Makie.jl/pull/2496) by @t-bltg was just merged into master, so now (April 1, 2023) it will be possible to do:

```julia
using CairoMakie

main() = begin
  paraboloid = (x, y) -> 10(x^2 + y^2)
  x = range(-3, 3; length = 100)
  y = range(-3, 3; length = 200)
  z = paraboloid.(x, y')

  fig, ax, hm = heatmap(x, y, z; interpolate = true)
  Colorbar(fig[1, 2], hm)

  contour!(
    ax, x, y, z;
    color = :red, levels = 0:10:100, labels = true,
    labelsize = 15, labelfont = :bold, labelcolor = :orange
  )

  save("contour_labels_2d.png", fig)
  fig
end

main()

```

That produces:

 ![imagen](https://global.discourse-cdn.com/julialang/original/3X/f/c/fcbba4ce479e5a64a5c6d5b730ec28f9000eb7e1.jpeg)

---

<div class="post-metadata">

**Author:** ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)\
**Post date:** [September 8, 2023, 8:43am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/6 "2023-09-08T08:43:48Z")

</div>

@aramirezreyes I’m running the latest version of CairoMakie and I cannot plot the labels as in your example. Would you or someone else be able to check if they can replicate this please?

Using the code above, I get this figure:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/b/3b62930b89cec8623e7890ccd4be80309d315c77.jpeg)

Info:

```julia
(@v1.8) pkg> status CairoMakie
Status `C:\Users\mert4417\.julia\environments\v1.8\Project.toml`
⌃ [13f3f980] CairoMakie v0.9.2
Info Packages marked with ⌃ have new versions available and may be upgradable.

```

```julia
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, tigerlake)
  Threads: 16 on 16 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 16

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [September 8, 2023, 8:59am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/7 "2023-09-08T08:59:18Z")

</div>

You’re not running the current CairoMakie. See the note in the package status that you pasted:

```julia
⌃ [13f3f980] CairoMakie v0.9.2
Info Packages marked with ⌃ have new versions available and may be upgradable.

```

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [September 8, 2023, 9:37am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/8 "2023-09-08T09:37:38Z")

</div>

Yes. To complement, this change was introduced in `Make 0.19.5`.

What does your

```julia
>]st -m Makie

```

Say?

---

<div class="post-metadata">

**Author:** ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)\
**Post date:** [September 8, 2023, 11:02am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/9 "2023-09-08T11:02:09Z")

</div>

> [@sijo](#):
>
> You’re not running the current CairoMakie. See the note in the package status that you pasted:
> 
> ```julia
> ⌃ [13f3f980] CairoMakie v0.9.2
> Info Packages marked with ⌃ have new versions available and may be upgradable.
> 
> ```

This was the result of `]status CairoMakie` after I’d done `]update CairoMakie` to check I was running the latest. Assumed therefore it was the most recent

---

<div class="post-metadata">

**Author:** ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)\
**Post date:** [September 8, 2023, 11:04am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/10 "2023-09-08T11:04:01Z")

</div>

> [@aramirezreyes](#):
>
> `>]st -m Makie`

```julia
(@v1.8) pkg> st -m Makie
Status `C:\Users\mert4417\.julia\environments\v1.8\Manifest.toml`
⌅ [ee78f7c6] Makie v0.18.2
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`

```

This looks like my answer, thanks

---

<div class="post-metadata">

**Author:** ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)\
**Post date:** [September 8, 2023, 11:18am UTC](https://discourse.julialang.org/t/how-to-add-value-labels-on-top-of-contours-in-makie/59242/11 "2023-09-08T11:18:38Z")

</div>

`]update` upgraded everything and now it works like a charm. Thanks!
