24

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};
gsamaras
  • 1,443

3 Answers3

22

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=discard (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}

engineer
  • 801
Jake
  • 232,450
3

using nan solves the problem

x   ind2   ind3
1   5      7
2   9      nan
3   11     15
2

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

Peter Grill
  • 223,288
  • 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 07:02