Plots.jl
Plots.jl copied to clipboard
[BUG] `primary:=false` series messes with legend entries
Details
Here's a MWE. The series in the middle, primary := false
, messes with the order of the legend entries in the plots coming after it
struct Foo end
@recipe function fooplot(f::Foo)
layout --> 2
subplot := 1
@series begin
linecolor -> [1 2]
label := ["1" "2"]
randn(3, 2)
end
@series begin
linecolor --> 1
primary --> false
[1]
end
subplot := 2
@series begin
linecolor := [1 2]
label := ["1" "2"]
randn(3, 2)
end
end
plot(Foo())
look at the legend in the second subplot
Backends
Both GR and plotly
Versions
Plots.jl version: Plots v1.25.10
Backend version (]st -m <backend(s)>
): GR v0.64.0
Output of versioninfo()
:
julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD Ryzen 9 5900X 12-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, znver3)
Environment:
JULIA_NUM_THREADS = 12
JULIA_EDITOR = code
JULIA_SSH_NO_VERIFY_HOSTS = gitlab.cognibotics.net
JULIA_PKG_PRECOMPILE_AUTO = 1
JULIA_NUM_PRECOMPILE_TASKS = 6
I think this has the same cause as https://discourse.julialang.org/t/odd-behaviour-of-custom-labels-in-plot-recipes/76057/12, namely bad interaction of the argument cycling with recipes.
For now I'd advise to construct only a single series per @series
block.