How to change legends place with Plots, gr()?



I’m using Plots and GR, and can’t find a way to change the legends location in a plot. As I understand currently I can’t do it with Plots, there’s no keyword argument for it (correct me if I’m wrong).
Can someone please shoew me a method how to do that? I would prefer a solution with Plots with GR backend.

using Plots

Possible keywords are :right, :left, :top, :bottom, :inside, :best, :legend, :topright, :topleft, :bottomleft, :bottomright

:outertopright not yet supported :frowning: (in GR)


Tank you! That is what I’m looking for.


Is there support for specifying number of columns in the legend list? (Like in PyPlot…)




Does any know whether there are any efforts underway to allow legends to be placed outside the plot? Unfortunately, placing the legend within the plot often obscures the data.


If you use PyPlot.jl directly, it is possible with something like:

legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0)


Thank you. That might suffice as a workaround. Do you have any idea if its is possible to access that method via Plots using low level functions or something of that nature? The reason I ask is that using PyPlot directly would require rewriting a fair amount of code. Thanks.


I am no expert in this but this seems to work:

using Plots; pyplot()
pt = plot(1:10, 1:10, label="A", legend=false)
pt.o[:legend](bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0)

pt.o seems to give the plot’s PyObject under the hood so you can work with it much like any other PyObject from PyCall.jl. Of course all valid matplotlib.pyplot functions are also valid in this context using PyCall syntax.

When you display pt, it will not show the legend, but if you display pt.o, it will show.


Nice solution. Thanks!


I tried to run this code but I get the following error message:

No handles with labels found to put in legend.

I’m using Jupyter with Julia 1.0.1. Do you have any idea what I might be doing wrong?


I am not getting your error, but it doesn’t seem to be working anymore. I am not sure what’s wrong and I don’t have time to dig into it, sorry. Someone else may be more useful.