# Makie: text rotation in data coordinates

Hi,
I’m trying to plot text “along a curve”. I’ve managed to put it in the correct place (using data space coordinates)
but the orientation is wrong since data space angle is not the same as screen space angle.
Is there a trick? Can I query the axis about it’s scaling to convert between the two?

Yes you could take the ax.finallimits observable and the ax.scene.px_area observable for example to compute the right angles. You have a curve in data coordinates that you want to have the text follow? Do you have an example picture?

1 Like

Thank you, @jules !
That was just what I needed.

Here’s an example script for future readers:

``````fig = Figure(resolution=(900,400))
ax1 = Axis(fig[1,1], title="uncorrected")
ax2 = Axis(fig[1,2], title="corrected")

myfun(x) = 1/4 * x^2
myslope(x) = 1/2 *x
xs = -2:0.1:2

lines!(ax1, xs, myfun.(xs))
lines!(ax2, xs, myfun.(xs))

display(fig)
# Correction factor
# angle conversion factors
Δx_data, Δy_data = ax2.finallimits[].widths
Δx_screen, Δy_screen = ax2.scene.px_area[].widths
correction_factor = Δx_data / Δx_screen * Δy_screen / Δy_data

for xtext in -2:0.5:2
text!(ax1, string(xtext),
position = (xtext, myfun(xtext)),
rotation = atan(myslope(xtext)),
align = (:center, :baseline),
)
text!(ax2, string(xtext),
position = (xtext, myfun(xtext)),
rotation = atan(correction_factor*myslope(xtext)),
align = (:center, :baseline),
)
end
fig
``````

1 Like