I have a rather big figure with two rows of plots where the first row has one y-axis and the second row has another y-axis. I would like to set the axis limits for these two sets of y-axes without having to write \nextgroupplot[ymin=###,ymax=###]
for every plot, for example using \pgfplotsset{group/every plot/.style={ymin=###,ymax=###}}
but this doesn't seem to work.
Here's an example of what I want to achieve
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=3 by 2,every plot/.style={xmin=0,xmax=10}},width=4cm,height=6cm]
\nextgroupplot[ylabel={Quantity1 [unit1]},ymin=0,ymax=5,title={First conditions}]
\addplot {x};
\nextgroupplot[ymin=0,ymax=5,title={Second conditions}]
\addplot {x};
\nextgroupplot[ymin=0,ymax=5,title={Third conditions}]
\addplot {x};
\nextgroupplot[ylabel={Quantity2 [unit2]},ymin=100,ymax=400]
\addplot {400/x^.5};
\nextgroupplot[ymin=100,ymax=400]
\addplot {400/x^.5};
\nextgroupplot[ymin=100,ymax=400]
\addplot {400/x^.5};
\end{groupplot}
\end{tikzpicture}
\end{document}
Which gives:
Here's the code with attempted simplifications (and correction for LaRiFaRi's comment):
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=3 by 2,every plot/.style={xmin=0,xmax=10}},width=4cm,height=6cm]
\pgfplotsset{group/every plot/.append style={ymin=0,ymax=5}}
\nextgroupplot[ylabel={Quantity1 [unit1]},title={First conditions}]
\addplot {x};
\nextgroupplot[title={Second conditions}]
\addplot {x};
\nextgroupplot[title={Third conditions}]
\addplot {x};
\pgfplotsset{group/every plot/.style={ymin=100,ymax=400}}
\nextgroupplot[ylabel={Quantity2 [unit2]}]
\addplot {400/x^.5};
\nextgroupplot
\addplot {400/x^.5};
\nextgroupplot
\addplot {400/x^.5};
\end{groupplot}
\end{tikzpicture}
\end{document}
But unfortunately, this messes up the axes for the second group of plots. Is there another way to set the axis limits for several plots?
Best Answer
I would say this is not a bug but a feature. Using
\pgfplotsset
after the first\nextgroupplot
is (most probably) the same as using that inside of anaxis
environment and thus is scoped to that. Said that I also recommend starting a newgroupplot
environment. About "repeating" the options: Just create a style collecting all stuff that is in common and apply the differences to each newgroupplot
environment.For more details please have a look at the comments in the code.