Makie: Put text at arbitrary position outside the frame

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


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:

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)

1 Like

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?)

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

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.

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.

1 Like