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.

Suppose to have a file .dat like this:

 -4.8767000e+000 -2.9142000e-001             NaN             NaN             NaN             NaN
 -3.9017000e+000 -4.1404000e-001             NaN             NaN             NaN             NaN
 -3.7141000e+000             NaN             NaN -2.6865000e-001             NaN             NaN
 -2.8267000e+000 -8.5233000e-001             NaN             NaN             NaN             NaN
 -2.7641000e+000             NaN -3.0872000e-001             NaN             NaN             NaN
 -2.5488000e+000             NaN             NaN -4.1579000e-001             NaN             NaN
 -1.9125000e+000             NaN             NaN             NaN             NaN -1.3021000e-001
 -1.8869000e+000             NaN             NaN             NaN -2.4675000e-001             NaN
 -1.7165000e+000             NaN -5.1881000e-001             NaN             NaN             NaN
 -1.6755000e+000 -1.6062000e+000             NaN             NaN             NaN             NaN
 -1.4064000e+000             NaN             NaN -6.1630000e-001             NaN             NaN
 -8.3837000e-001             NaN             NaN             NaN -5.1510000e-001             NaN
 -7.9259000e-001             NaN             NaN             NaN             NaN -4.0836000e-001
 -6.4542000e-001 -2.2095000e+000             NaN             NaN             NaN             NaN
 -5.4987000e-001             NaN -7.4848000e-001             NaN             NaN             NaN
 -4.2297000e-001             NaN             NaN -1.2681000e+000             NaN             NaN
  2.0480000e-001             NaN -1.9436000e+000             NaN             NaN             NaN
  2.1333000e-001             NaN             NaN             NaN -9.8248000e-001             NaN
  3.3584000e-001             NaN             NaN             NaN             NaN -1.2254000e+000
  4.4876000e-001 -2.3614000e+000             NaN             NaN             NaN             NaN
  7.7282000e-001             NaN             NaN -1.8424000e+000             NaN             NaN
  1.3886000e+000             NaN             NaN             NaN -1.7607000e+000             NaN
  1.4709000e+000             NaN -2.4598000e+000             NaN             NaN             NaN
  1.5644000e+000 -2.3726000e+000             NaN             NaN             NaN             NaN
  1.8937000e+000             NaN             NaN -2.1788000e+000             NaN             NaN
  2.3417000e+000             NaN             NaN             NaN -1.9949000e+000             NaN
  2.4386000e+000             NaN             NaN             NaN             NaN -2.1213000e+000
  2.5903000e+000             NaN -2.7040000e+000             NaN             NaN             NaN
  2.9174000e+000             NaN             NaN -2.3792000e+000             NaN             NaN
  3.4874000e+000             NaN             NaN             NaN -2.4042000e+000             NaN
  3.5796000e+000             NaN             NaN             NaN             NaN -2.2296000e+000
  3.7549000e+000             NaN -2.8123000e+000             NaN             NaN             NaN
  3.9405000e+000             NaN             NaN -2.5407000e+000             NaN             NaN
  4.6521000e+000             NaN             NaN             NaN -2.5125000e+000             NaN

If I plot thse data with the following minimal code:

\documentclass{report}

\usepackage[showframe,
            margin=2.5cm,
            left=3cm]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.4}

\begin{document}
\centering
\begin{tikzpicture}
\begin{axis}

\foreach \n in {1,2,...,5}{
\addplot table[x index = 0,
               y index = \n]{DATA.dat};
}
\end{axis}
\end{tikzpicture}
\end{document}

PGFplots skip the first row. It means that the y points in the first row are not plotted!!

Is it because PGFplots see it like a row with column names?

Is it possible to solve this problem?

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

If there are non-numeric entries in the first row, PGFplots assumes that this is a header row that contains the titles for the columns. You can force PGFplots to interpret the first row as a data row using header=false.

\documentclass{article}
\usepackage[]{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{testdata.dat}
0   NaN 1   1
1   1   2   NaN
2   1.2 NaN 2
3   2   3   1
\end{filecontents}

\usepackage{pgfplots}
\pgfplotsset{compat=1.4}

\begin{document}
\centering
\begin{tikzpicture}
\begin{axis}

\foreach \n in {1,...,3}{
\addplot table[
    header=false,
    x index = 0,
    y index = \n]{testdata.dat};
}
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Dear @Jake, how is the solution modified if UnDf is used instead of NaN in the table? –  Kadir Apr 24 '13 at 8:49
    
@user1632456: You can teach the number parser to treat UnDf like NaN. Would you mind opening another question for this? That way, it would be easier for others with the same problem to find the solution. –  Jake Apr 24 '13 at 9:08
    
Dear @Jake, thanks for the comment. I have opened another question: tex.stackexchange.com/questions/110441/… –  Kadir Apr 24 '13 at 9:17
add comment

Your Answer

 
discard

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.