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.
Asked
Active
Viewed 176 times
1
Stefan Pinnow
- 29,535
user2536125
- 1,165
-
1We're not good at reading minds, sorry. More information is needed. – egreg Apr 03 '16 at 21:21
-
@egreg, closers Really? I thinks it's quite clear what the OP wants. – Torbjørn T. Nov 02 '16 at 15:35
-
@TorbjørnT. Then provide an answer! ;-) – egreg Nov 02 '16 at 15:41
-
@egreg Understanding the question is not the same as being able to answer it. – Torbjørn T. Nov 02 '16 at 15:42
-
@TorbjørnT. Then provide at least minimal example that demonstrates the question (if you think it is worth to invest your time in a question which the user abondoned 7 month ago). – Ulrike Fischer Nov 02 '16 at 16:08
-
1I think that this needs a minimal working example to justify reopening. – Nov 02 '16 at 20:32
1 Answers
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.
\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
