Problems trying to rotate annotations in a plot

Hi,

I am trying to write some annotations in a plot, but instead of horizontally, I would like them to do that vertically.

I am using Julia 0.6.4. My code is like:

using Plots # Notice: I'm not using Pyplot package, but just the back-end!
pyplot()

# Initialize plot
wanted_font = font(9, "georgia") 
fig_2 = plot(
tickfont  = wanted_font, legendfont = wanted_font, guidefont = wanted_font,
xlabel = "My x-axis", ylabel = "My y-axis",
size = (600,300),  
legend = false, grid = false,
xmin = 0, ymin = 0,
)

scatter!(fig_2,
x_vector, y_vector,
c = [1], marker = (:circle, 2), markerstrokewidth = 0.1,
)

how_many = 50 # After how many points to draw a vertical line
vline!(fig_2, [x_vector[how_many],
xaxis = [0, 1000], yaxis = [0, 500],
annotations=(x_vector[how_many], 250, text("My description", font(9,"georgia"))),
leg = false,
)

This piece of code simply plots an horizontal annotation saying “My description”. Does anyone have any suggestion on how to rotate such annotation?

Note: I have already checked https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337 but if I try using e.g.: text(4, 0.5, "hello", rotation=30)
I get the following error message: function text does not accept keyword arguments.

Thank you in advance!

Something like this should work:

julia> plot(1:3)

julia> font = text("").font
Plots.Font("sans-serif", 14, :hcenter, :vcenter, 0.0, RGB{N0f8}(0.0,0.0,0.0))

julia> font.rotation = 90
90

julia> annotate!(2,2.5, text("text", font))
2 Likes

@mauro3 thanks very much, this works!!

For future reference, just a minor correction: in order to rotate of 90 degrees, what works is:

font.rotation = pi/2

Apparently angles need to be expressed in radiants!

In Julia 1.1 with a fresh-ish Plots.jl I had to use degrees. In Julia 0.6 it is indeed radians.

2 Likes