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 have a \pgfplotstable with data (loaded from a file) like this one:

  s       f
  0.0     95.9638
  0.2380665    160.565
  0.511     190.435
  0.705    270.435
  1.0         455.9638

I need to generate this \pgfplotstable rearranging rows and columns of \data:

  s       f
  1.0         270.435
  0.705    190.435
  0.511     160.565
  0.2380665    95.9638
  0.0     <95.9638 or any other value>

The rows are in inverted order and the second column displaced 1 element above.

Any advice, please?

share|improve this question
up vote 5 down vote accepted

You can do this a bit simpler by using inbuilt methods to reverse the order and create a new column that contains the shifted values:

  s       f
  0.0     95.9638
  0.2380665    160.565
  0.511     190.435
  0.705    270.435
  1.0         455.9638


\pgfplotstablesort[sort cmp=float >]{\data}{\originaldata}

    create on use/shifted/.style={
    create col/expr={\nextrow{\secondcolumnname}*1}}

    columns/shifted/.style={column name=\secondcolumnname}]\data

\addplot table {\originaldata};
\addplot table [y=shifted] {\data};

plot of original and shifted data

share|improve this answer
Thanks, but I need the new table for drawing porpouses: \addplot[..] table \customdata. Is there any way to create the new table instead of \pgfplotstabletypeset? – Fernando Nadal Jun 24 '11 at 21:47
@Fernando: You don't need to save the table in a new macro, you can just call it directly in pgfplots. I've edited my answer to show this. – Jake Jun 25 '11 at 4:05
I see now.. Thanks again !! – Fernando Nadal Jun 25 '11 at 22:27

I did it!


\pgfmathsetmacro\ymax{\pgfmathresult - 1}


  \pgfmathsetmacro\newrow{\ymax - \pgfplotstablerow}

  \ifnum \pgfplotstablerow < \ymax
    \pgfmathsetmacro\filaant{\ymax - \pgfplotstablerow - 1}
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.