When I want to set a style using groupplot
, I will do something like this:
\begin{groupplot}[
group style={
group size=1 by 2,
vertical sep=1cm,
},
]
However, I've found that if I try to save that as a style using pgfplotsset
, like so:
\pgfplotsset{
mygroup/.style={
group style={
group size=1 by 2,
vertical sep=1cm,
},
},
}
applying the style seems to ignore the contents of the group style
key. The value of other keys are observed and correctly applied, but not that of group style
. If I want to make changes to the keys in the group
path, I have to specify them entirely:
\pgfplotsset{
mygroup/.style={
group/group size=1 by 2,
group/vertical sep=1cm,
},
}
But this seems to me to be an odd, non-standard behaviour, since you wouldn't use this way of writing when specifying options to \begin{groupplot}
.
Is this the expected behaviour? What is the recommended way to define group styles in pgfplotsset
? Here's a MWE, where you can uncomment the different options:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary[pgfplots.groupplots,calc]
\pgfplotsset{
compat=1.12,
mygroup/.style={
group style={
group size=1 by 2,
vertical sep=1cm,
},
every axis plot/.append style={
smooth,
}
},
mygroupb/.style={
group/group size=1 by 2,
group/vertical sep=1cm,
every axis plot/.append style={
smooth,
}
},
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
% This style works without "group style"
% mygroupb,
% This style doesn't apply "group style"
% mygroup,
% But adding it manually here works
% group style={
% group size=1 by 2,
% vertical sep=1cm,
% },
]
\nextgroupplot
\addplot+[samples=5,domain=-3:3] {exp(-x^2+1)};
\addplot+[samples=5,domain=-3:3] {exp(-x^2)};
\addplot+[samples=5,domain=-3:3] {exp(-x^2-1)};
\nextgroupplot
\addplot+[samples=5,domain=-3:3] {exp(-x^2+1)};
\addplot+[samples=5,domain=-3:3] {exp(-x^2)};
\addplot+[samples=5,domain=-3:3] {exp(-x^2-1)};
\end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}
.show value
or.show code
and you will see if pgfkeys does forget those settings. (not guarantee.) If this is the case, you might need to pack your settings into anevery foobar
, which is executed at the right time..show value
to try this out. Particularly since, as you note, this is scoped and will change. I made a small test withevery axis plot/.style={extra description/.code={\pgfkeys{/pgfplots/group style/.show value}}}
, but that definitely did not show anything useful. In any case, this seems to me to be a bug. I just hope someone can show me why it's not.\message{}
. Otherwise you cannot distinguish whether it is forgotten or overridden.groupplot
env to get to work directly. Instead do:.../.style={...,/pgfplots/group/.cd,!allgroupstyles!}
. I agree, it isn't beautiful, but it will work.