TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to get the max/min value from a specific column table via function \findmax and \findmin in order to use it in ymin and ymax. I really dont get how \pgfplotstablesort function works. What would be perfect is to call \findmax{YAmax,YA,YAmin} and get back the maximum value of those 3 columns.


    \pgfplotstablesort[sort key={#1},sort cmp={float >}]{\sorted}{data.dat}%

X   YA  YAmin   YAmax   YB  YBmin   YBmax
1   5   4   6   6   5   7
2   3   2   5   7   5   9
3   6   1   9   9   7   13
4   4   2   6   6   1   11
5   0   -1  3   3   0   5
6   1   -3  6   1   -1  2


\pgfplotsset{width=3cm,scale only axis}


\addplot [very thick,smooth,red,solid]  table [x=X, y=YA]   {data.dat}; 
\addplot [very thick,smooth,red,dotted]  table [x=X, y=YAmin]   {data.dat}; 
\addplot [very thick,smooth,red,dotted]  table [x=X, y=YAmax]   {data.dat}; 

\addplot [very thick,smooth,red,solid]  table [x=X, y=YB]   {data.dat}; 
\addplot [very thick,smooth,red,dotted]  table [x=X, y=YBmin]   {data.dat}; 
\addplot [very thick,smooth,red,dotted]  table [x=X, y=YBmax]   {data.dat}; 

share|improve this question
Maybe you can use Christians answer in the pgfplots features mailing list. – Martin Heller Apr 7 '13 at 15:59
up vote 2 down vote accepted

Finally done it.

Just created a function that finds the extrema of a chosen column of the external table.

  % Starting value for max : 0

  % Parsing each element of the first column
  \pgfplotsinvokeforeach {0,...,5}{
    \ifthenelse{ \pgfplotsretval >\mymax  }
    {\pgfmathtruncatemacro{\mymax}{\pgfplotsretval}} % valid
    {}  %invalid
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.