# Keeping \`textlabel\`s at a fixed size in Makie

**URL:** <https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [July 3, 2025, 5:38am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435 "2025-07-03T05:38:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 3, 2025, 5:38am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/1 "2025-07-03T05:38:29Z")

</div>

I’m using Makie.jl to visualize pathfinding in mazes, like in the image below.

 ![mapf](https://global.discourse-cdn.com/julialang/original/3X/f/4/f483dd839885e483d189109cbe49cecb3c24ae87.png)

The maze itself is rendered with `Makie.image` and the agents on top of it with `Makie.textlabel`, using a [custom background shape](https://docs.makie.org/dev/reference/plots/textlabel#Custom-Background-Shapes).

My issue here is that the agents are too big. I would like to be able to specify their size as a function of the dimensions of the image (the ones visible on the axes), so that the font and circle scale with the maze. Instead, what I see when zooming is that the `textlabel`s keep a constant size, which is not the behavior I want (although I understand it for readability purposes).  
Does anyone know how to achieve this fixed size?

Minimum working example (where the size is adaptive):

```julia
using GLMakie

textlabel(
    rand(10),
    rand(10),
    map(string, 1:10);
    shape=Circle(Point2f(0), 1.0f0),
    shape_limits=Rect2f(-sqrt(0.5), -sqrt(0.5), sqrt(2), sqrt(2)),
    keep_aspect=true,
)

```

---

<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, 2025, 11:08am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/2 "2025-07-03T11:08:25Z")

</div>

I don’t think `textlabel` currently has the ability to do text in something other than screen space. But you don’t really need the adaptive machinery of `textlabel` for what you want. You just want circles with numbers in them, right? So `poly` and `text` with `markerspace = :data` does the job:

```julia
f = Figure()
ax = Axis(f[1, 1], aspect = DataAspect())
n = 20
heatmap!(ax, randn(n, n))
x = rand(1:n, n)
y = rand(1:n, n)
poly!(Circle.(Point2d.(x, y), 0.4), color = :white)
text!(
    ax,
    x,
    y;
    text = map(string, 1:n),
    fontsize = 0.4,
    align = (:center, :center),
    markerspace = :data,
)
f

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 3, 2025, 11:17am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/3 "2025-07-03T11:17:50Z")

</div>

More efficient would be to use scatter:

```julia
f = Figure()
ax = Axis(f[1, 1], aspect = DataAspect())
n = 20
heatmap!(ax, randn(n, n))
x = rand(1:n, n)
y = rand(1:n, n)
scatter!(ax, Point2d.(x, y), color = :white, marker=Circle, markersize=0.8, markerspace=:data)
text!(
    ax,
    x,
    y;
    text = map(string, 1:n),
    fontsize = 0.4,
    align = (:center, :center),
    markerspace = :data,
)
f

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 3, 2025, 11:21am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/4 "2025-07-03T11:21:16Z")

</div>

Thanks for the suggestions, this seems to be exactly what i need!  
Follow up: since I’m working in a grid world, I’d like the grid lines to remain visible on top of the image / heatmap (which will always be black and white). Is there any way to do that using the keyword arguments to image/heatmap ? Or maybe by putting it somehow behind the axis grid lines?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 3, 2025, 11:52am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/5 "2025-07-03T11:52:52Z")

</div>

Update: I managed that part with `linesegments!`. The end result looks great, thanks again!

---

<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, 2025, 3:07pm UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/6 "2025-07-03T15:07:56Z")

</div>

For such a grid, hlines and vlines are even simpler to set up than linesegments

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [July 3, 2025, 4:51pm UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/7 "2025-07-03T16:51:04Z")

</div>

If you want to be lazy you can specify the axis’s minor ticks to form the grid 😃

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 4, 2025, 7:14am UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/8 "2025-07-04T07:14:24Z")

</div>

That was my initial thought but the grid is hidden by the image I plot on top of it

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [July 8, 2025, 1:12pm UTC](https://discourse.julialang.org/t/keeping-textlabel-s-at-a-fixed-size-in-makie/130435/9 "2025-07-08T13:12:16Z")

</div>

Ah you can always `translate!(img_plot, 0, 0, -100)` or so but yeah. I don’t think the grid line z level is an attribute, but it should be one.
