# PGFPlotsX: Options from string in grouplot

**URL:** <https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426>\
**Category:** General Usage\
**Tags:** plotting, pgfplotsx\
**Created:** [July 17, 2018, 6:56am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426 "2018-07-17T06:56:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [July 17, 2018, 6:56am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426/1 "2018-07-17T06:56:09Z")

</div>

Hello,

I am creating a fairly complicated groupplot with a shared legend. Since each subplot has its own combination of axis labels, I created options and then I would like to put the into groupplot as an options, like follows

```julia
@pgf gp = GroupPlot({group_style = { group_size = "1 by 1",}, height = "6cm", width = "6cm"});
opts = "title = {title}, ylabel = {y label}, xlabel = {x label} "
push!(gp,opts)

```

which generates following latex code

```julia
\begin{groupplot}[group style={group size={1 by 1}}, height={6cm}, width={6cm}]
    title = {title}, ylabel = {y label}, xlabel = {x label}
\end{groupplot}

```

But I would like the code to be

```julia
\begin{groupplot}[group style={group size={1 by 1}}, height={6cm}, width={6cm}]
   \nextgroupplot[\title = {title}, ylabel = {y label}, xlabel = {x label}]
\end{groupplot}

```

Is there a way, how to achieve this, or I have to put the nextgroupplot by myself, as

```julia
@pgf gp = GroupPlot({group_style = { group_size = "1 by 1",}, height = "6cm", width = "6cm"});
opts = "title = {title}, ylabel = {y label}, xlabel = {x label} "
push!(gp,"\\nextgroupplot["*opts*"]")

```

It is sort of hacky solution, but it works. I am afraid that I am missing the “correct” way to do it.

Thanks for answers.

---

<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:** [July 17, 2018, 7:14am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426/2 "2018-07-17T07:14:27Z")

</div>

See [the manual on `GroupPlot`](https://kristofferc.github.io/PGFPlotsX.jl/latest/man/axislike.html#GroupPlot-1), in particular

> `Options` (ie from `@pgf {}`) will emit a `\nextgroupplot` with the given options,

so eg

```julia
julia> @pgf gp = GroupPlot({group_style = { group_size = "1 by 1",}, height = "6cm", width = "6cm"});

julia> opts = @pgf { "title = {title}, ylabel = {y label}, xlabel = {x label}" };

julia> push!(gp,opts);

julia> print_tex(gp)
\begin{groupplot}[group style={group size={1 by 1}}, height={6cm}, width={6cm}]
    \nextgroupplot[title = {title}, ylabel = {y label}, xlabel = {x label}]
\end{groupplot}

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 17, 2018, 7:19am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426/3 "2018-07-17T07:19:22Z")

</div>

```julia
opts = @pgf { title = "title", ylabel = "y label", xlabel = "x label" };

```

should also work.

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [July 17, 2018, 7:36am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426/4 "2018-07-17T07:36:53Z")

</div>

Hi Kristoffer,

thanks for a swift answer. I have read this from the manual, but the trick I need is to generate the options from string as shown above. It is because I construct the options incrementally, for example

```julia
opts = "tile = {title}"
i == 1&& opts*= "..."
mod(i,2) == 1 && opts*=",ylabel = {ylabel}"
i>=5 && opts*=",xlabel = {xlabel}"

```

after which I would like to exec `push!(gp,opts);`

Tomas

---

<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:** [July 17, 2018, 7:40am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426/5 "2018-07-17T07:40:43Z")

</div>

You _can_ construct options incrementally, see

[https://kristofferc.github.io/PGFPlotsX.jl/latest/man/options.html#Modifying-options-after-an-object-is-created-1](https://kristofferc.github.io/PGFPlotsX.jl/latest/man/options.html#Modifying-options-after-an-object-is-created-1)

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [July 17, 2018, 7:54am UTC](https://discourse.julialang.org/t/pgfplotsx-options-from-string-in-grouplot/12426/6 "2018-07-17T07:54:27Z")

</div>

Thanks, that has solved the problem.
