# Makie: text rotation in data coordinates

**URL:** <https://discourse.julialang.org/t/makie-text-rotation-in-data-coordinates/74031>\
**Category:** General Usage\
**Tags:** question, plotting, makie\
**Created:** [January 4, 2022, 2:12pm UTC](https://discourse.julialang.org/t/makie-text-rotation-in-data-coordinates/74031 "2022-01-04T14:12:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [January 4, 2022, 2:12pm UTC](https://discourse.julialang.org/t/makie-text-rotation-in-data-coordinates/74031/1 "2022-01-04T14:12:11Z")

</div>

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?

---

<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:** [January 4, 2022, 2:55pm UTC](https://discourse.julialang.org/t/makie-text-rotation-in-data-coordinates/74031/2 "2022-01-04T14:55:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [January 4, 2022, 3:24pm UTC](https://discourse.julialang.org/t/makie-text-rotation-in-data-coordinates/74031/3 "2022-01-04T15:24:25Z")

</div>

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

Here’s an example script for future readers:

```julia
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

```

 ![textorientation](https://global.discourse-cdn.com/julialang/original/3X/2/2/22b17ebfb44a697e50f5f5eb8b316f9f355e3d10.png)
