# Rotate text such that it aligns with the gradient of a line

**URL:** <https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [March 23, 2021, 4:44pm UTC](https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799 "2021-03-23T16:44:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [March 23, 2021, 4:44pm UTC](https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799/1 "2021-03-23T16:44:45Z")

</div>

Hello, I’m trying to make some text line up with a line from A to B, the problem is that the angle is fixed and not relative to the aspect ratio of the figure. I suppose a way to do it is to get the size of the figure and adjust, but I’m not sure how to do that either. Any help is appreciated.

Here’s a MWE to demonstrate my problem:

```julia
using Plots

points = [[0.1, 0.3], [0.3, 0.5]]
midpoint = ((points[1][2] - points[1][1], points[2][2] - points[2][1]) ./ 2) .+ (points[1][1], points[2][1])
p = Plots.plot(xlims = (0,1), ylims = (0,1))
Plots.plot!(points...)
Plots.annotate!(p, midpoint[1], midpoint[2] + 0.1, Plots.text("30", 10, :dark, rotation = 30))
Plots.plot!(size = (500, 500))

```

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [March 23, 2021, 5:04pm UTC](https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799/2 "2021-03-23T17:04:52Z")

</div>

You mean, [like this](https://www.generic-mapping-tools.org/GMT.jl/dev/gallery/scripts_agu/decorated_II/)?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/6/463ae5d9c9ab7383aaa8b2f1165138c3ed4e7097.png)

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [March 23, 2021, 5:19pm UTC](https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799/3 "2021-03-23T17:19:05Z")

</div>

Yes but for a straight line. Although that is very pretty.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [March 23, 2021, 5:29pm UTC](https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799/4 "2021-03-23T17:29:30Z")

</div>

Well, for straight lines is even simpler. Same principle but simpler because no need to generate the spiral. Just two points are needed.

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [March 23, 2021, 6:12pm UTC](https://discourse.julialang.org/t/rotate-text-such-that-it-aligns-with-the-gradient-of-a-line/57799/5 "2021-03-23T18:12:54Z")

</div>

Anything using the GR backend for Plots? I’m not sure if you can mix and match, and I’ve done anything else using GR.
