Double legend with twinx()

I am trying to plot this:

plot(1:10, 1:10, seriestype = :bar, label = “1”, alpha = 0.4, legend = :left )
plot!(twinx(), 1:10, 501:510, label = “2”)

but I get two different legends and I want to get only one. (I moved the first legend to the left otherwise it is covered by the second one)

1 Like

A hack:

plot(1:10, 1:10, seriestype = :bar, label = "1", alpha = 0.4)
plot!(1:10, NaN.*(1:10), label = "2", linecolor=:green, grid=false, legend=:left) 
plot!(twinx(), 1:10, 501:510, legend=false, linecolor=:green)

PS: please quote your code PSA: how to quote code with backticks

3 Likes

Thank you!

1 Like