I am not able to use the legend keyword to move legends using the PlotlyJS backend. For example, this does not work:
julia> using Plots, Blink
julia> plotlyjs()
Plots.PlotlyJSBackend()
julia> p = plot(Plots.fakedata(50,5),w=3)
julia> plot!(p, legend = :bottom)
the resulting plot still has 5 legend entries, in the upper left. Is this intentional?
It's not the behavior I want, but I can't figure out how to have
independent legends in Plotly, or how to reposition it. If anyone knows how
please let me know.
On Fri, Nov 18, 2016 at 10:19 PM tcovert [email protected] wrote:
I am not able to use the legend keyword to move legends using the
PlotlyJS backend. For example, this does not work:julia> using Plots, Blink
julia> plotlyjs()
Plots.PlotlyJSBackend()julia> p = plot(Plots.fakedata(50,5),w=3)
julia> plot!(p, legend = :bottom)
the resulting plot still has 5 legend entries, in the upper left. Is this
intentional?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tbreloff/Plots.jl/issues/574, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA492lstT7gr6Jyl69cdYR7J-uIshNjvks5q_mqygaJpZM4K3JVc
.
You can actually specify legend position in x and y coordinates in the layout with PlotlyJS:
using PlotlyJS
traces = GenericTrace[]
l = Layout(; legend = attr(x = 0., y= 0.))
for i = 1:5
trace = scatter(; x = 1:10, y = rand(10), name = "draw $i")
push!(traces,trace)
end
plot(traces,l)
Here for example x = 0, y = 0 corresponds to bottom left. I'm not sure about independent entries.
Thanks! I'll get to this eventually but a PR from someone else would speed the process. ;)
I've tried implementing a simple way to get x,y position of legend from keyword (say [0,0] for bottom left, [0.5, 0] for bottom, [1,0] for bottom right), but it has a couple of issues:
1) The automated positioning of the legend with PlotlyJS is often not very good, because the cartesian axes are inside the figure and the legend will likely end up on top of them. There would need to be some method to programmatically detect a smart position (taking the axis position into account) or the user should be given the possibility of manually inputting coordinates.

2) Given that this happens via the layout, in case of several subplots all the legends are in the same position, which is determined by the position of the legend of the last subplot. This may be an inherent problem of plot.ly

Should this be closed?
Now you can position by inputting by hand the coordinates which works nicely. I've realized that some of the default values (say for :bottomleft) are not spectacular, but I'm not sure how to put it exactly above the x axis/to the right of the y axis (maybe just inputting better constant coordinates?). Anyway they're defined here if you wanna take a stab.
In connection with this it'd actually be nice to let legend accept a tuple with the exact legend positions, also for the other backends.
Also, I think that since Jan 18, the default legend positions for PlotlyJS kept the ridiculous values that I gave them and I'm still not sure what's a good way to set them... They are here
Most helpful comment
In connection with this it'd actually be nice to let
legendaccept a tuple with the exact legend positions, also for the other backends.