CairoMakie Legend Line Too Short

Hello,

I am trying to determine how I can increase the line thickness of the lines in the legend.

Please consider the following MWE and resulting image. The lines in the legend are too short and it is hard to tell which is dashed and which is solid (I realize in this case the markers can be used to discern them, please ignore that for the sake of the example).

How can I increase the little segments of line in in the legend so it is clearer which line style corresponds to which legend entry?

using CairoMakie, LinearAlgebra

x = LinRange(0, 1, 10)
y1 = sin.(2π * x)
y2 = x .^ 2

begin
    fig = Figure()
    ax = Axis(fig[1, 1])
    scatterlines!(x, y1, label="Line 1")
    scatterlines!(x, y2, label="Line 2")
    axislegend("My Legend", position=:lb)
    fig
end

mwe

1 Like

This post made me laugh out loud. It’s like Makie is trying to mess with you.

You can increase the width of the patchsize of the Legend which will increase the line widths as well.

2 Likes

It’s far from the defaults though… I think @TI36XPro has a lot of configuration that’s not included in the MWE. With the given code I see this:

We can adjust the legend line length using patchsize as suggested by @jules, replacing the axislegend line with

axislegend("My Legend", position=:lb, patchsize=(50,20))

6 Likes

I tried axislegend("My Legend", position=:lb, patchsize=10) and I get the following error ERROR: BoundsError: attempt to access Int64 at index [2]

Edit: Nevermind. Didn’t realize patchsize has to be a tuple. I’ve fixed it. Ended up using patchsize=(50,10) for now. Thank you!

Correct - I forgot I had a theme applied separately that is not included in the MWE. Although the theme makes no changes to patchsize so still not clear how or why it got so small. Either way, it is fixed!

still not clear how or why it got so small

I think you just themed all the other stuff to be quite big :slight_smile: