I am new to pgfplotstable, I am trying to read gnuplot exported table in pgfplotstable.

gnuplot script:

set samples 91
set table "file.dat"
set angles degrees
plot [0:90] sin(x),cos(x),tan(x);
unset table

gnuplot table file.dat is given below (5 points given to be concise):

# Curve 0 of 3, 91 points
# Curve title: "sin(x)"
# x y type
 0  0  i
 1  0.0174524  i
 2  0.0348995  i
 3  0.052336  i
 4  0.0697565  i
 5  0.0871557  i

# Curve 1 of 3, 91 points
# Curve title: "cos(x)"
# x y type
 0  1  i
 1  0.999848  i
 2  0.999391  i
 3  0.99863  i
 4  0.997564  i
 5  0.996195  i

# Curve 2 of 3, 91 points
# Curve title: "tan(x)"
# x y type
 0  0  i
 1  0.0174551  i
 2  0.0349208  i
 3  0.0524078  i
 4  0.0699268  i
 5  0.0874887  i

Note: It's possible to read table header and format (all data arranged in columns) given below compared to the above case (all data arranged sequentially)

# A B C 
  1 2 3 
  4 5 7
  8 9 10


Is it possible to read custom format ASCII file in pgfplotstable by \pgfplotstableset{} or any other workarounds in gnuplot to make it read well and typeset in pgfplotstable?


Initially I thought you wanted to plot the data but reading your question again it seems you just want to set it as a table using pgfplotstable you can do something like this although I'm not sure pgfplotstable is really helping in this case, by the time you've re-arranged the data to be read by \pgfplotstabletypeset you could simply write it as a longtable, however...

enter image description here

[update for non integer first column]



  \iterateb \let\iterateb\relax}




\def\ca*1# Curve*2 of *3,*4 points*5!!{%

\def\cb*1# Curve title: "*2"*3!!{%

\def\cc*1 *2 *3 *4!!{%



\read\myin to \tmp
  \expandafter\cb\tmp# Curve title: "\relax"!!%
    \expandafter\ca\tmp# Curve of \relax, points!!%
      \expandafter\cc\tmp. . . !!%
        \expandafter\edef\csname my-\the\@tempcnta-\the\@tempcntb\endcsname{\ifnum\@tempcnta=1 \x\space\fi\y}
    \expandafter\let\csname my-\the\@tempcnta-title\endcsname\title


\xdef\row{\row\space \csname my-\the\@tempcnta-title\endcsname}

\xdef\row{\row\space \csname my-\the\@tempcnta-\the\@tempcntb\endcsname}

\xdef\tmp{\noexpand\pgfplotstabletypeset[row sep=\noexpand\\, begin table=\noexpand\begin{longtable}, 
end table=\noexpand\end{longtable}



  • How to extend on Eg: # Curve 2 of 6(data_sets), 991(numb_pnts) points to typeset with five significant digits after decimal ? – texenthusiast Apr 16 '13 at 21:50
  • @texenthusiast changing the end of the code to sci,precision=5]{\mytable} does something – David Carlisle Apr 16 '13 at 22:01

Although not a great low level TeX answer like above, surprisingly overlooked previously and found today that using pgfplotstable options ignore chars={\i} to read full gnuplot table file.dat in two columns and select equal part entry of to rearrange two columns into equal rows of 3 columns. But could not find pgfplotstable options to read multiple headers("sin(x)","cos(x)" and "tan(x)") automatically.

enter image description here

\pgfplotstableset{begin table=\begin{longtable},end table=\end{longtable},%
every head row/.style={before row=\toprule,after row=\midrule},%
every last row/.style={after row=\bottomrule},%
every even row/.style={before row={\rowcolor[gray]{.8}}}%
display columns/0/.style={select equal part entry of={0}{3},column name=$x$},%
display columns/1/.style={select equal part entry of={0}{3},column name=$sin(x)$},%
display columns/2/.style={select equal part entry of={1}{3},column name=$cos(x)$},%
display columns/3/.style={select equal part entry of={2}{3},column name=$tan(x)$},%
precision=5,ignore chars={\i}]{file.dat}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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