# How to control legend position with PGFPlotsX

**URL:** <https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018>\
**Category:** Visualization\
**Tags:** plotting, pgfplotsx\
**Created:** [August 24, 2018, 10:57pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018 "2018-08-24T22:57:53Z")\
**Posts on this page:** 11\
**Page:** 1

<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:** [August 24, 2018, 10:57pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/1 "2018-08-24T22:57:53Z")

</div>

If I do

```julia
@pgf p = Axis({
                xlabel = "Distance [m]",
                ylabel = "Temperature [degree Kelvin]",
                title = "",
                legend = "pos south east"
            },
            …
            );

```

I get

```julia
PGFPlotsX.print_tex(p)
\begin{axis}[xlabel={Distance [m]}, ylabel={Temperature [degree Kelvin]}, title={}, legend={pos south east}]
    \addplot[color={red}, mark={x}]

```

~~but~~~~ I ~~~~need~~ `legend pos =south east` . ~~Has~~~~ anyone ~~~~solved~~~~ this ~~~~already~~? ~~Would~~~~ you ~~~~share~~?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 25, 2018, 12:45am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/2 "2018-08-25T00:45:06Z")

</div>

```julia
legend_pos = "south east"

```

---

<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:** [August 25, 2018, 1:32am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/3 "2018-08-25T01:32:41Z")

</div>

Splendid! It worked. Should I go see about an update to the documentation? (Or is it perhaps already there?)

---

<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:** [August 25, 2018, 4:05am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/4 "2018-08-25T04:05:18Z")

</div>

I also found that one could insert directly strings into the options array, which are directly passed to latex.  
Like this `"legend pos={south east}",`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 25, 2018, 5:09am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/5 "2018-08-25T05:09:35Z")

</div>

PGFPlotsX has documentation on how to interface with [pgfplots](http://mirrors.ctan.org/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf), while the documentation of the latter should be used for actual plotting constructs. On a TeXLive installation,

```nohighlight
$ texdoc pgfplots

```

or similar should open the docs.

That said, the manual [has an example](https://kristofferc.github.io/PGFPlotsX.jl/latest/examples/juliatypes.html#DataFrames.jl-1) with `legend_pos`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 25, 2018, 5:44am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/6 "2018-08-25T05:44:20Z")

</div>

Don’t to that. It works, but PGFPlotsX will treat `"legend pos={south east}"` as an option with that name (and no value). It is better to do what @fredrikekre suggested.

BTW, I made a PR to the documentation, suggestions welcome:

[https://github.com/KristofferC/PGFPlotsX.jl/pull/124](https://github.com/KristofferC/PGFPlotsX.jl/pull/124)

---

<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:** [August 25, 2018, 1:51pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/7 "2018-08-25T13:51:24Z")

</div>

That’s great.

What about the trick with legend\_pos getting converted to legend pos? That is non-obvious and except for that example there is no mention in the manual yet.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 25, 2018, 2:08pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/8 "2018-08-25T14:08:36Z")

</div>

On the contrary, I think they are explained in the [Options](https://kristofferc.github.io/PGFPlotsX.jl/latest/man/options.html) section:

> Keywords can be entered
> 
> 1. as Julia identifiers, which is useful for keywords with no spaces (eg `smooth` ),
> 
> 2. separated by underscores, which are replaced by spaces (eg `only_marks` will appear in LaTeX code as `only marks` ),
> 
> 3. or quoted as strings, eg `"very thick"` .

If you think we could make the documentation better, issues/PRs are always welcome.

---

<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:** [August 25, 2018, 2:10pm UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/9 "2018-08-25T14:10:25Z")

</div>

Excellent. I missed it!

---

<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, 10:13am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/10 "2023-02-18T10:13:04Z")

</div>

> [@fredrikekre](#):
>
> `east`

How would I do this if I wanted it to be outside the axis?

Kind regards

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [February 18, 2023, 11:53am UTC](https://discourse.julialang.org/t/how-to-control-legend-position-with-pgfplotsx/14018/11 "2023-02-18T11:53:18Z")

</div>

Please open a new thread. Don’t hijack existing threads, especially when they’re old.
