PGFPlotsX: Options from string in grouplot

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

@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

\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

\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

@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.

See the manual on GroupPlot, in particular

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

so eg

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}
1 Like
opts = @pgf { title = "title", ylabel = "y label", xlabel = "x label" };

should also work.

1 Like

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

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

You can construct options incrementally, see

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

1 Like

Thanks, that has solved the problem.

2 Likes