1

Having several subplots generated using groupplots library, I would like to automatically detect the data range in each subplot, and specify two yticklabels only (ymin and ymax). Because the data range in different subplots varies, I have to detect the minimum and maximum programmatically.

Stefan Pinnow
  • 29,535
user2536125
  • 1,165

1 Answers1

1

I think this would answer the question. pgfplots needs to figure out the range of the data anyway, so the numbers are available in the macros \pgfplots@data@ymin and \pgfplots@data@ymax, just not in a "public" interface.

Borrowing an idea from Jake's answer to Tufte like axis with pgfplots, we can say

\makeatletter
\newcommand\pgfplotsdataymin\pgfplots@data@ymin
\newcommand\pgfplotsdataymax\pgfplots@data@ymax
\makeatother

and then add

ytick={\pgfplotsdataymin,\pgfplotsdataymax}

to the groupplot options.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepgfplotslibrary{groupplots}
\makeatletter
\newcommand\pgfplotsdataymin\pgfplots@data@ymin
\newcommand\pgfplotsdataymax\pgfplots@data@ymax
\makeatother
\begin{document}
\begin{tikzpicture}

\begin{groupplot}[
 group style={
   group size=1 by 3,
   x descriptions at=edge bottom},
 height=3cm,width=7cm,
 ytick={\pgfplotsdataymin,\pgfplotsdataymax}
]

\nextgroupplot
\addplot {rnd+1};

\nextgroupplot
\addplot {rnd*3+2};

\nextgroupplot
\addplot {rnd*6+7};

\end{groupplot}
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688