# Makie: Put text at arbitrary position outside the frame

**URL:** <https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [October 23, 2023, 4:56pm UTC](https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322 "2023-10-23T16:56:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 23, 2023, 4:56pm UTC](https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322/1 "2023-10-23T16:56:20Z")

</div>

From a past thread (see below), I learned how to put arbitrary text outside the frame. But, am I right that it’s impossible or extremely tedious to put text at an **arbitrary position**?

I’ve plotted the following figure, which is okay, but there is too much space between the y axes. One solution is to move the y-axis labels above the upper ends of the corresponding y axes.

I tried `text!(ax1, . . . )` but the text appears only within the frame. Is it possible to switch off the clipping behavior?

This is just an example. I sometimes put some text on the figure inside and outside and sometimes even across an axis.

![tmp](https://global.discourse-cdn.com/julialang/original/3X/6/a/6a27a85f97f128dc36f43cacd69d3abf50998113.png)

* * *

> [@Text outside of Axis with Makie](https://discourse.julialang.org/t/text-outside-of-axis-with-makie/97888):
>
> Is it possible, using Makie.jl, to add text outside of an axis? For instance, in using CairoMakie fig = Figure() ax = Axis(fig[1, 1]) [image] I want to add text right on the top-left on the plot outside of the axis itself. I tried e.g. text!(ax, -5, 10; text = L"$ $Upper") but of course that just changes the axis limits and puts it inside.

---

<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:** [October 23, 2023, 10:20pm UTC](https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322/2 "2023-10-23T22:20:09Z")

</div>

The Figure contains a scene which spans the whole area. If you want to place something freely that’s usually the easiest way. For example:

```julia
text!(fig.scene, Point3f(100, 100, 0), text = "Test 1", space = :pixel)
text!(fig.scene, Point3f(0.5, 0.8, 0), text = "Test 2", space = :relative)

```

Note that you may need to adjust the z values of these plots to get the render order correct. (pixel is between -10\_000 and 10\_000, relative between -1 and 1)

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 24, 2023, 1:31am UTC](https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322/3 "2023-10-24T01:31:33Z")

</div>

> `text!(fig.scene, . . . )`

Thanks!!! I didn’t know “scene”. Does that mean that you can also plot arbitrary polygons and lines on the scene using the scene coordinates? (← I wrote this before I search the Internet. Where do you find a documentation or tutorial about plotting on the scene?)

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 24, 2023, 3:54am UTC](https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322/4 "2023-10-24T03:54:19Z")

</div>

Yes, I’ve just tried and found that you can plot lines directly onto the scene:

```julia
lines!(fig.scene, [0.08, 0.93], [0.13, 0.13],
       space = :relative,
       color=:grey65, linewidth=1, linestyle=:dot)

```

The remaining problem I wan to solve is to find the relationship between the user coordinates within the “axes” to the “scene” coordinates.

Currently I need a lot of trial and error to place the lines at the desirable positions on the “scene”, which is because I don’t know how to relate the user-coordinate positions within the axes to the “scene” coordinates.

---

<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:** [October 24, 2023, 9:44am UTC](https://discourse.julialang.org/t/makie-put-text-at-arbitrary-position-outside-the-frame/105322/5 "2023-10-24T09:44:54Z")

</div>

Plotting to a Scene is no different from plotting to an Axis. An Axis just keeps track of a few things to update itself before placing your plot in `axis.scene`.

You can transform data coordinates from a given scene into (global) pixel coordinates with `Makie.shift_project(ax.scene, pos)` or `Makie.shift_project(ax.scene, ax.scene.plots[1], pos)` dependeing on the Makie version. That’s an internal function though, so it’s not documented.
