# How do I annotate datapoints

**URL:** <https://discourse.julialang.org/t/how-do-i-annotate-datapoints/83709>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [July 3, 2022, 4:49pm UTC](https://discourse.julialang.org/t/how-do-i-annotate-datapoints/83709 "2022-07-03T16:49:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chiem](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Chiem](https://discourse.julialang.org/u/Chiem)\
**Post date:** [July 3, 2022, 4:49pm UTC](https://discourse.julialang.org/t/how-do-i-annotate-datapoints/83709/1 "2022-07-03T16:49:19Z")

</div>

Hello everyone, I have been using the Makie.jl package (more specifically CairoMakie) for the creation of figures for the project I am working on. I am currently creating a scatterplot and would like to annotate my datapoints with their identity; however, it is not clear to me how to do this. The only thing I can find about it in the documentation is the following:

```julia
annotations(strings::Vector{String}, positions::Vector{Point})

```

However, the position of the datapoints in my figure have both an x and a y. Does anyone know how to implement this in a scatterplot?

This is my code currently:

```julia
x=[1.0,2.0,3.0]
y=[1.0,2.0,3.0]
annotation=["A","B","C"]
location=[1.0 1.0 1.0
2.0 2.0 2.0
3.0 3.0 2.0]

fig = Figure()
tit = "Testannotation"
xlab = "x"
ylab = "y"

ax = Axis(fig[1, 1], xlabel = xlab, ylabel = ylab, title = tit)#
scatter!(x,y)
annotations!(annotation,location)

```

no matter what I do i always get the letters in the bottom left corner. I tried a vector and matrices and even single numbers for location. Somehow the function never produces an error regardless of what i put in and the position of the letters never changes. they are all displayed on top of each other in the bottom left corner.

Example figure:

 ![Testannotation](https://global.discourse-cdn.com/julialang/original/3X/4/4/445cbe05975ba59b08204c96646ea26c49a53200.png)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Chiem](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Chiem](https://discourse.julialang.org/u/Chiem)\
**Post date:** [July 3, 2022, 5:59pm UTC](https://discourse.julialang.org/t/how-do-i-annotate-datapoints/83709/2 "2022-07-03T17:59:21Z")

</div>

So after searching a lot i figured that text!() is probably what I am looking for which is outlined in the documentation linked here:

[https://makie.juliaplots.org/stable/examples/plotting\_functions/text/](https://makie.juliaplots.org/stable/examples/plotting_functions/text/)

However, all my attempts of using this function result in an error. Likewise, all of the examples presented in the documentation also result in the following error:

```julia
LoadError: MethodError: no method matching layout_text(::Int64, ::Float32, ::FreeTypeAbstraction.FTFont, ::Tuple{Symbol, Symbol}, ::Quaternionf, ::MakieCore.Automatic, ::Float64, ::ColorTypes.RGBA{Float32}, ::ColorTypes.RGBA{Float32}, ::Int64)

```

Examples i tried to run:

```julia
using CairoMakie

f = Figure()

Axis(f[1, 1], aspect = DataAspect(), backgroundcolor = :gray50)

scatter!(Point2f(0, 0))
text!(0, 0, text = "center", align = (:center, :center))

circlepoints = [(cos(a), sin(a)) for a in LinRange(0, 2pi, 16)[1:end-1]]
scatter!(circlepoints)
text!(
    circlepoints,
    text = "this is point " .* string.(1:15),
    rotation = LinRange(0, 2pi, 16)[1:end-1],
    align = (:right, :baseline),
    color = cgrad(:Spectral)[LinRange(0, 1, 15)]
)

f

```

and

```julia
using CairoMakie

aligns = [(h, v) for v in [:bottom, :baseline, :center, :top]
                 for h in [:left, :center, :right]]
x = repeat(1:3, 4)
y = repeat(1:4, inner = 3)
scatter(x, y)
text!(x, y, text = string.(aligns), align = aligns)
current_figure()

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 3, 2022, 6:46pm UTC](https://discourse.julialang.org/t/how-do-i-annotate-datapoints/83709/3 "2022-07-03T18:46:44Z")

</div>

If an example from the docs doesn’t work that almost 100% of the time means that you need to use the newest versions, because the examples are regenerated on every docs update so they must work.

In this case, the option to do `text!(x, y)` where x and y are scalars was only added recently, which is where the error comes from.

---

<div class="post-metadata">

**Author:** ![Chiem](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Chiem](https://discourse.julialang.org/u/Chiem)\
**Post date:** [July 3, 2022, 7:05pm UTC](https://discourse.julialang.org/t/how-do-i-annotate-datapoints/83709/4 "2022-07-03T19:05:51Z")

</div>

Indeed I am able to run the examples after updating my packages. thanks for the help.
