# How to draw a textbox around a text in Makie.jl?

**URL:** https://discourse.julialang.org/t/how-to-draw-a-textbox-around-a-text-in-makie-jl/75672
**Category:** Visualization
**Tags:** question, makie
**Created:** [February 2, 2022, 4:23pm UTC](https://discourse.julialang.org/t/how-to-draw-a-textbox-around-a-text-in-makie-jl/75672 "2022-02-02T16:23:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [February 2, 2022, 4:23pm UTC](https://discourse.julialang.org/t/how-to-draw-a-textbox-around-a-text-in-makie-jl/75672/1 "2022-02-02T16:23:52Z")

</div>

In Makie.jl, how can I draw a box around a text? More specifically, I’d like to draw the bounding box of a given text that I’ve plotted using the `text!` function.

In fact, it is even better if I could use the existing `Textbox`, which looks gorgeous, and already has all the customization I need regarding line and box colors. But so far `Textbox` is a layoutable, while I want it to be plottable at arbitrary locations on an axis.

[https://makie.juliaplots.org/stable/examples/layoutables/textbox/index.html#textbox](https://makie.juliaplots.org/stable/examples/layoutables/textbox/index.html#textbox)

---

<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: [February 2, 2022, 11:57pm UTC](https://discourse.julialang.org/t/how-to-draw-a-textbox-around-a-text-in-makie-jl/75672/2 "2022-02-02T23:57:01Z")

</div>

The two step projection makes this a bit more complicated. With the text position in data space and the textsize in pixel units you’d need

```julia
fig, ax, p = text("Test", position = Point2f(2))
scene = campixel(ax.scene);
bb = Rect2f(boundingbox(
    p.plots[1][1][], 
    Makie.to_ndim(Point3f, Makie.project(ax.scene, p.plots[1].position[]), 0), 
    Makie.to_rotation(p.plots[1].rotation[])
))
mesh!(scene, bb, color = :yellow, shading = false)
lines!(scene, bb)
translate!(scene, 0, 0, -1)
fig

```

`boundingbox(p)` seems to fall back on some default method that isn’t useful. `boundingbox(p.plots[1])` does use the right method but assumes the text position and textsize to be in the same space. So you need to project position into pixel space first and use the boundingbox above. The result is in pixelspace so you need to plot in on a scene with a pixel camera.
