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

**URL:** <https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [November 24, 2017, 5:00pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294 "2017-11-24T17:00:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [November 24, 2017, 5:00pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/1 "2017-11-24T17:00:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [November 24, 2017, 5:30pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/2 "2017-11-24T17:30:22Z")

</div>

```julia
using Plots
plot(randn(10,3),legend=:bottomleft)

```

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

:outertopright not yet supported ☹ (in `GR`)

---

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [November 24, 2017, 6:42pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/3 "2017-11-24T18:42:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 24, 2017, 7:26pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/4 "2017-11-24T19:26:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [November 24, 2017, 7:44pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/5 "2017-11-24T19:44:34Z")

</div>

No

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 19, 2018, 7:52pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/6 "2018-09-19T19:52:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [September 20, 2018, 3:16am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/7 "2018-09-20T03:16:24Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 20, 2018, 10:25am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/8 "2018-09-20T10:25:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [September 20, 2018, 11:08am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/9 "2018-09-20T11:08:04Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 20, 2018, 11:14am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/10 "2018-09-20T11:14:52Z")

</div>

Nice solution. Thanks!

---

<div class="post-metadata">

**Author:** ![mroavi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mroavi/32/8804_2.png) [@mroavi](https://discourse.julialang.org/u/mroavi)\
**Post date:** [November 14, 2018, 11:00am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/11 "2018-11-14T11:00:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [November 14, 2018, 12:49pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/12 "2018-11-14T12:49:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CanLi1](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@CanLi1](https://discourse.julialang.org/u/CanLi1)\
**Post date:** [April 11, 2019, 1:24am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/13 "2019-04-11T01:24:54Z")

</div>

Hi,

I saw you post here. I’m encountering the same problem. Have you fixed it? Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@simon](https://discourse.julialang.org/u/simon)\
**Post date:** [May 17, 2019, 11:08am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/14 "2019-05-17T11:08:22Z")

</div>

Encountered the same problem with gr(). I haven’t tried yet, but check this post. [julia - How to move the legend to outside the plotting area in Plots.jl (GR)? - Stack Overflow](https://stackoverflow.com/questions/45097631/how-to-move-the-legend-to-outside-the-plotting-area-in-plots-jl-gr)

---

<div class="post-metadata">

**Author:** ![ljschumacher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ljschumacher/32/8233_2.png) [@ljschumacher](https://discourse.julialang.org/u/ljschumacher)\
**Post date:** [August 7, 2019, 9:22am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/15 "2019-08-07T09:22:50Z")

</div>

It would be desirable to have this functionality enabled in the gr backend without the layout hack mentioned on stackoverflow

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 7, 2019, 11:00am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/16 "2019-08-07T11:00:32Z")

</div>

Should exist now. [https://github.com/JuliaPlots/Plots.jl/pull/2018](https://github.com/JuliaPlots/Plots.jl/pull/2018)

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 3, 2019, 4:41am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/17 "2019-10-03T04:41:56Z")

</div>

> [@jheinen](#):
>
> outertopright not yet supported ☹ (in `GR` )

`:outerbottom` and `:outertoporight` etc are supported now!

---

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [November 26, 2019, 12:59pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/18 "2019-11-26T12:59:40Z")

</div>

When I use `legend=:bottomright` the legend is not placed close enough to the bottom (see picture). Is there a way to make it move more to the bottom so it won’t hide the data?

 ![53](https://global.discourse-cdn.com/julialang/original/3X/e/2/e2a328d4f93421c0ef58f39f1dc7da9fa9afe86a.png)

---

<div class="post-metadata">

**Author:** ![MikeMoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikemoore/32/11823_2.png) [@MikeMoore](https://discourse.julialang.org/u/MikeMoore)\
**Post date:** [December 13, 2019, 11:39am UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/19 "2019-12-13T11:39:20Z")

</div>

Same happens with :topright and :topleft. The legend is placed too far away from the top border overlapping many times the data in the plot. Moving the legend up for the top ones and down for the bottom ones will be helpful.

---

<div class="post-metadata">

**Author:** ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)\
**Post date:** [December 17, 2019, 11:06pm UTC](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294/20 "2019-12-17T23:06:41Z")

</div>

> [@mkborregaard](#):
>
> Should exist now. [https://github.com/JuliaPlots/Plots.jl/pull/2018](https://github.com/JuliaPlots/Plots.jl/pull/2018)

Should this be able to work with `heatmap` as well? It does not appear so from my trials

[Next page](https://discourse.julialang.org/t/how-to-change-legends-place-with-plots-gr/7294.md?page=2)
