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.

I am using PGFPlot with external table data. However, some values are missing for some plots. This causes data in column 2 does not exists error. Is there a way to solve this. The value does not exists and all data for x, ind3 should be considered as {(1,7)(3,15)}. Is there a way to overcome this problem?

The following is the data file I tried to create:

x   ind2   ind3
1   5      7
2   9      
3   11     15

And plot commands

\addplot[color=blue, mark=x] table[x=x, y=ind2] {performance.data};

\addplot[color=red, mark=+] table[x=x, y=ind3] {performance.data};

Thanks in advance

share|improve this question
    
Are the entries in your datafile separated by tabs or by an unspecified number of spaces? –  Jake Sep 18 '11 at 10:09
    
@jake: they are tabs, but not single tabs. As much as needed to be pretty. –  Cem Kalyoncu Sep 19 '11 at 7:03

3 Answers 3

up vote 9 down vote accepted

As you noted yourself, using nan as a placeholder for empty values solves the problem. It's worth pointing out that you also have the choice of whether to just skip the empty value and connect the surrounding data points, or whether the graph should be interrupted when it encounters an empty value. You can control this behaviour using unbounded coords=skip (which is the default behaviour) or unbounded coords=jump.

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

\begin{filecontents}{performance.data}
x   ind2   ind3
0  2     4
1  5     7
2  9 nan
3 11  15
4 10  15
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ymax=20]
    \addplot table {performance.data};
    \addplot table [y=ind3] {performance.data};
    \addplot +[unbounded coords=jump,yshift=0.5cm] table [y=ind3] {performance.data}; % Plot shifted upwards to show difference
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
This might come handy, thanks –  Cem Kalyoncu Sep 19 '11 at 7:23

This seems to work fine for me (with current version of TeXLive2011). If this does not solve your problem, please post a MWE.

\documentclass{article}
\usepackage{pgfplots}

\begin{filecontents}{performance.data}
x   ind2   ind3
1   5      7
2   9      
3   11     15
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}
    \addplot[color=blue, mark=x] table[x=x, y=ind2] {performance.data};
    \addplot[color=red,  mark=+] table[x=x, y=ind3] {performance.data};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
interesting result, value in 2 shouldnt be 7. May be its different in external files. I have solved the problem. Adding nan instead of leaving empty removes the entry at 2. –  Cem Kalyoncu Sep 19 '11 at 7:02

using nan solves the problem

x   ind2   ind3
1   5      7
2   9      nan
3   11     15
share|improve this answer

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.