Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase spacing/padding between legend labels in Plots.jl

Tags:

julia

plots.jl

I am using Plots.jl with the GR backend to produce some plots in JuliaLang. I have noticed that when using LaTeXStrings.jl to produce Latex strings in the legend labels that the labels are close together. To illustrate what I'm referring to, I've edited the JuliaPlots linestyle example to use Latex strings in the legend labels. The code is as follows:

using Plots; gr()
using LaTeXStrings

styles = filter((s->begin
            s in Plots.supported_styles()
        end), [:solid, :dash, :dot, :dashdot, :dashdotdot])

styles = reshape(styles, 1, length(styles))
n = length(styles)
y = cumsum(randn(20, n), dims = 1)

plot(y, line = (5, styles), label = [L"s^{ol}_{id}" L"d^{as}_h" L"d^{o}_{t}" L"d^{ash}_{dot}" L"dash^{dot}_{dot}"], legendtitle = "linestyle")

The above code produces the following plot:

Plots.jl with LaTeXStrings in the legend

As you can see, the subscripts of one label are very close to the superscripts of the label directly beneath. Similarly for the legend title.

I would like to increase the spacing/padding between each label so there is a gap between the super- and sub-scripts of each label, but have no idea how to do it.

like image 614
crispyninja Avatar asked Oct 21 '20 14:10

crispyninja


1 Answers

More advanced legend formatting seems to be available only for pyplot() backend. However, when working with gr() I sometimes use this very ugly trick:

plot(y, line = (5, styles), label = [L"^{s^{ol}_{id}}" L"^{d^{as}_h}" L"^{d^{o}_{t}}" L"^{d^{ash}_{dot}}" L"^{dash^{dot}_{dot}}"],legendtitle = "linestyle",legendfontsize=14.0)

enter image description here

like image 174
Przemyslaw Szufel Avatar answered Oct 27 '22 15:10

Przemyslaw Szufel