# Makie.jl - How can I have a label on top of an image plot?

**URL:** https://discourse.julialang.org/t/makie-jl-how-can-i-have-a-label-on-top-of-an-image-plot/74536
**Category:** Visualization
**Tags:** makie
**Created:** [January 13, 2022, 9:18am UTC](https://discourse.julialang.org/t/makie-jl-how-can-i-have-a-label-on-top-of-an-image-plot/74536 "2022-01-13T09:18:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![klafyvel](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@klafyvel](https://discourse.julialang.org/u/klafyvel)
#### Post date: [January 13, 2022, 9:18am UTC](https://discourse.julialang.org/t/makie-jl-how-can-i-have-a-label-on-top-of-an-image-plot/74536/1 "2022-01-13T09:18:08Z")

</div>

Hi,  
I am trying to label some plots containing images, but somehow I fail to have a label on top of an image. Here is a minimal working example :

```julia
using GLMakie, FileIO
img = load(assetpath("cow.png"))
f = Figure()
image(f[1, 1], img, axis = (title = "Default",))

Box(f[1,1], halign=:left, valign=:top, tellwidth=false, tellheight=false, color=:white, width=35, height=30)
Label(f[1,1], "(a)", padding=(5,5,0,0), halign=:left, valign=:top, tellwidth=false, tellheight=false, textsize=20)
f

```

This gives the following result :

 ![cow_nok](https://global.discourse-cdn.com/julialang/original/3X/e/0/e0590c7beadef5f16a0c144460a4b2d2d73f9a64.png)

I saw in the documentation that for CairoMakie it’s recommended to play with `translate!`, but you can’t `translate!` an `Label`, so I’m a bit stuck here.

Thanks for your help !

---

<div class="post-metadata">

### Author: ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)
#### Post date: [January 13, 2022, 2:24pm UTC](https://discourse.julialang.org/t/makie-jl-how-can-i-have-a-label-on-top-of-an-image-plot/74536/2 "2022-01-13T14:24:14Z")

</div>

You can translate! plots and scenes, but not layout elements. To make the Box and the Label visible you probably need something like

```julia
ax, p = image(fig[1, 1], ...)
translate!(p, 0, 0, -1)

```

If you want more control over your label you could try making it manually.

```julia
mesh!(fig.scene, Rect2f(200, 200, 50, 20))
lines!(fig.scene, Rect2f(200, 200, 50, 20))
p = text!(fig.scene, "(a)", position = Point2f(205, 205), align = (:left, :bottom))

```

`fig.scene` is in pixel units which is probably more convenient than axis. `boundingbox(p)` might also be helpful.

---

<div class="post-metadata">

### Author: ![klafyvel](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@klafyvel](https://discourse.julialang.org/u/klafyvel)
#### Post date: [January 25, 2022, 4:39pm UTC](https://discourse.julialang.org/t/makie-jl-how-can-i-have-a-label-on-top-of-an-image-plot/74536/3 "2022-01-25T16:39:28Z")

</div>

Hi, sorry for the late answer.

I tried again today, and after some messing around, here is what i got :

```julia
using GLMakie, FileIO

img = load(assetpath("cow.png"))
fig = Figure()
image(fig[1, 1], img, axis = (title = "Default",))
image(fig[1, 2], img, axis = (title = "Default",))
image(fig[1, 3], img, axis = (title = "Default",))
image(fig[2, 1], img, axis = (title = "Default",))
image(fig[2, 2], img, axis = (title = "Default",))
image(fig[2, 3], img, axis = (title = "Default",))

labels = [
          "a" "b" "c" 
          "d" "e" "f"
         ]
nb_rows,nb_cols = size(fig.layout)
square_size = 25
for i ∈ 1:nb_rows, j ∈ 1:nb_cols
  px_area = content(fig.layout[i,j]).scene.px_area[]

  x,y = px_area.origin
  _,h = px_area.widths

  b = poly!(fig.scene, 
            Point2f[
                    (x, y+h), 
                    (x+square_size, y+h), 
                    (x+square_size, y+h-square_size), 
                    (x, y+h-square_size)
                   ], 
            color = :white, 
            strokecolor = :black, 
            strokewidth = 1
           )
  t = text!(
            fig.scene, 
            labels[i,j], position = Point2f(x+12, y+h-25+12),
            align = (:center, :center), textsize=20,
           )
  translate!(b, 0, 0, 100)
  translate!(t, 0, 0, 100)
end

save("testfigure.png", fig)

```

And the result :

 ![testfigure](https://global.discourse-cdn.com/julialang/original/3X/8/9/8971b105e793fd8156ee4679c37b9156a37a065c.jpeg)

thanks a lot for the help @ffreyer !
