MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.43k stars 312 forks source link

Cycled + Linestyle + outside axis breaks with 0.20 #3462

Open bilderbuchi opened 11 months ago

bilderbuchi commented 11 months ago

I have been using Cycled to good effect to control the look of a number of plots I am placing in one figure. This worked well in 0.19.2, but when I recently upgraded to 0.20.2, precompilation of my package started to fail with

ERROR: Attribute linestyle was passed with an explicit Cycled value,e cycler for this plot type Lines{Tuple{Vector{Point{2, Float32}}}}.

The problem seems to crop up as soon as I

I managed to wrangle this example from the docs into a MWE that shows the regression:

using GLMakie
f = Figure()
ax = Axis(f[1, 1]) # if the ax is created outside with_theme, weird things happen
with_theme(
    Theme(
        palette=(color=[:red, :blue], linestyle=[:solid, :dash, :dot]),
        Lines=(cycle=Cycle([:color, :linestyle], covary=true),)
    )) do
    # creating f, ax here would work fine, but is not possible in my case

    # the normal cycle - works
    # lines!(ax, 0 .. 10, x -> sin(x) - 1)
    # lines!(ax, 0 .. 10, x -> sin(x) - 2)
    # lines!(ax, 0 .. 10, x -> sin(x) - 3)

    # Cycled+color - works
    # lines!(ax, 0 .. 10, x -> sin(x) - 5, color=Cycled(3))
    # lines!(ax, 0 .. 10, x -> sin(x) - 6, color=Cycled(2))
    # lines!(ax, 0 .. 10, x -> sin(x) - 7, color=Cycled(1))

    # Cycled+linestyle - errors with 
    # ERROR: Attribute `linestyle` was passed with an explicit `Cycled` value, 
    # but linestyle is not specified in the cycler for this plot type 
    # Lines{Tuple{Vector{Point{2, Float32}}}}.
    lines!(ax, 0 .. 10, x -> sin(x) - 5, linestyle=Cycled(3))
    lines!(ax, 0 .. 10, x -> sin(x) - 6, linestyle=Cycled(2))
    lines!(ax, 0 .. 10, x -> sin(x) - 7, linestyle=Cycled(1))

    f
end

Suspecting that a "naked" with_theme is missing something from the default theme that would be created along with a Figure/Axis when inside, I tried various combinations of merge(), update_theme! and with_theme to only update, not replace the theme in the with_theme block, but my Julia skills and MAkie API knowledge are not good enough.

To me, this looks like an undocumented regression (I checked the blog entry and changelog, but maybe I missed something). Is there a "new way" to do this, or a workaround for the time being?

bilderbuchi commented 10 months ago

The comment https://github.com/MakieOrg/Makie.jl/issues/2893#issuecomment-1521289522 could be relevant here.

Also, #2216 could be the same issue, but I'm not sure as it does not fit the regression behaviour/observation afaict, as this was filed before 0.19.2 was published.

1628 also seems related.