Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Basically I'm plotting many curves stacked one after the other in pseudo 3D to show transient behaviors. I need every x axis to be at the same place so I use a ymin and ymax optional entry for the axis environment. So far I used a variable that I changed by hand, but I'm wondering if there is a way to find a min and max from several external tables (18 here) and use it as a variable in my case.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can use \pgfplotstablevertcat{<newmacro>}{<filename>} to concatenate your datatables, then use \pgfplotstablesort{<newmacro>}{<table macro>} to sort the concatenated table, and get the largest (or smallest) value by extracting the first element of the sorted table using \pgfplotstablegetelem{<row>}{<col>}\of{<table macro>}.

Below are two scripts, \findmax and \findmin that take a comma separated list of filenames, concatenate the tables in those files and return the maximum/minimum.

finding extreme points


    \pgfplotsforeachungrouped \table in {#1} {%
    \pgfplotstablesort[sort key={1},sort cmp={float >}]{\sorted}{\concatenated}%

    \pgfplotsforeachungrouped \table in {#1} {%
    \pgfplotstablesort[sort key={1},sort cmp={float <}]{\sorted}{\concatenated}%

1 5
2 3
3 6
4 4
5 0
6 1

1 2
2 3
3 2
4 2
5 3
6 2

1 -2
2 0
3 -1
4 -1
5 -2
6 0



\pgfplotstabletypeset{dataA.dat} \hfill \pgfplotstabletypeset{dataB.dat} \hfill \pgfplotstabletypeset{dataC.dat} \hspace{4cm}\\[0.5cm]

Maximum value: \ymax\\
Minimum value: \ymin\\[0.5cm]

\pgfplotsset{ymin=\ymin,ymax=\ymax,width=3cm,scale only axis}
\addplot table {dataA.dat};

\addplot table {dataB.dat};

\addplot table {dataC.dat};
share|improve this answer
thanks a lot jake, exactly what I needed. –  ben paillard Aug 5 '11 at 13:26

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.