# How to control legend position with PGFPlotsX (move legend outside of axis)

**URL:** <https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx-move-legend-outside-of-axis/94832>\
**Category:** Visualization\
**Created:** [February 18, 2023, 11:59am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx-move-legend-outside-of-axis/94832 "2023-02-18T11:59:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [February 18, 2023, 11:59am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx-move-legend-outside-of-axis/94832/1 "2023-02-18T11:59:08Z")

</div>

I was advised to not “hijack” a thread, whatever that means, so making one more post.

Using PGFPlotsX, there is a field entry, legend\_pos, which allows for moving the legend inside of the axis.

How can I move the legend outside of the axis?

The thread in question where part of my issue is resolved: [How to control legend position with PGFPlotsX](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018)

And some example code:

```julia
x = range(0; stop =2*pi, length = 100)
@pgf GroupPlot(
    {
        group_style =
        {
            group_size="2 by 1",
            xticklabels_at="edge bottom",
            yticklabels_at="edge left",
            legend_pos = "south"
        },
        no_markers
    },
    {},
    PlotInc(Table(x, sin.(x))),
    PlotInc(Table(x, sin.(x .+ 0.5))),
    {},
    PlotInc(Table(x, cos.(x))),
    PlotInc(Table(x, cos.(x .+ 0.5)))),
    LegendEntry("Test")

```

Kind regards

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 18, 2023, 3:32pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx-move-legend-outside-of-axis/94832/2 "2023-02-18T15:32:47Z")

</div>

Try `legend_pos = "outer south"`.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [February 18, 2023, 3:48pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx-move-legend-outside-of-axis/94832/3 "2023-02-18T15:48:35Z")

</div>

> [@PetrKryslUCSD](#):
>
> legend\_pos = “outer south”

Unfortunately did not work.

Think I finally understood to look into pgfplots doc:

/pgfplots/legend pos=south west|south east|north west|north east|outer north east

> **[pgfplots.pdf](https://pgfplots.sourceforge.net/pgfplots.pdf)**
>
> 12.09 MB

page 261

And these are the only entries which should work. Perhaps there is a way to learn manually how to set it instead…

Kind regards
