Plots.jl Align legend labels, :right not working

No success either with legendfonthalign attribute.

A workaround is to left-pad the labels beforehand and use a font such as Courier so that the columns of characters are consistently aligned.
Computer Modern legends are not perfectly aligned but look better:

using LaTeXStrings, Plots; gr()

default(fontfamily="Computer Modern")
n = 3:2:23
x = 0:0.01:1; y = [3*n*exp.(-(n*(x .- 0.6)).^4) for n in n];
labels= permutedims(string.(n) .* " [s]")
n = maximum(length.(labels))
plot(x, y, label=lpad.(labels,n), legend=:outertopright)   # legendfont=font(6,"Courier")
plot!(xlabel=L"CVE",ylabel=L"Density") 

Legend with Courier font:
Plots_gr_legend_right_justification1

Legend with Computer Modern font:
Plots_gr_legend_right_justification2

1 Like