Removing duplicate legend items

In Plots.jl, is it possible to scan the Plot object legend items so I can remove the ones that are duplicated? Thanks!

Not sure if this is what you are looking for, but in case it helps:

using Plots; gr()

x = 1:10
p1 = plot(x, -x, label = "y = -x", c=:blue)
plot!(x, -x, label = "y = -x", c=:red)
plot!(x, 1 .- x, label = "y = 1 - x", c=:lime)

# this provides all series labels in the plot object p1:
labels = [x[:label] for x in p1.series_list]

# this removes repeated label 2 and makes line transparent:
p2 = deepcopy(p1)
p2.series_list[2][:label] = ""
p2.series_list[2][:linecolor] = RGBA{Float64}(0.0,0.0,0.0,0.0)
plot(p1, p2)

2 Likes

Yeap, this would work! Thanks :slight_smile: