0

I've got to a point where I have some data stored in a pgfplotstable macro. I want to remove a row from that macro (a line where some data is missing) and then further process the remaining data (doing some calculations) before plotting it with pgfplots. What I think would work would be if I could create a new macro containing all of the original data, omitting the row where data is missing. Is this possible? Or is there a better way? This is a simplified version of the situation I'm in. In this case I would want to remove the row 2,2,,. There may be multiple lines with missing data, and I don't necessarily know exactly which ones they are.

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotstableread[col sep=comma]{
  a,b,c,d
  1,1,1,1
  2,2,,
  3,3,3,3
}\data
\begin{document}
\pgfplotstabletypeset{\data}
\begin{tikzpicture}
  \begin{axis}
    \addplot table [x=a,y=b]{\data};
  \end{axis}
\end{tikzpicture}
\end{document}
1

Alas, \pgfplotstablevertcat does not support options. BTW, this assumes you know what rows to remove.

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotstableread[col sep=comma]{
  a,b,c,d
  1,1,1,1
  2,2,,
  3,3,3,3
}\data
\begin{document}
\pgfplotstablesave[skip rows between index={1}{2}]{\data}{filename}% create new file
\pgfplotstableread{filename}\data% read new file
\pgfplotstabletypeset{\data}
\begin{tikzpicture}
  \begin{axis}
    \addplot table [x=a,y=b]{\data};
  \end{axis}
\end{tikzpicture}
\end{document}
  • Thanks. I'd missed \pgfplotstablesave in the manual. I wonder if there is any way to do this if I don't know where the missing data might be? (Which could conceivably be more than one line.) I worry that with this approach I might get the index wrong one way or another. – Gareth Walker Oct 15 '18 at 17:47
  • 1
    You can search using \pgfplotstablegetelem, although I'm not sure how to distinguish missing data. You can remove multiple rows using \pgfplottableset[skip rows between...] in a loop. – John Kormylo Oct 16 '18 at 0:31
0

The answer and code provided here seems to do what I need.

Here's a sample file:

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable,pgfplotstablefilter}
\pgfplotstableread[col sep=comma]{
  a,b,c,d
  1,1,1,1
  2,2,,
  3,3,3,3
  4,4,4,4
  5,5,,
}\data
\begin{document}
\pgfkeys{/pgfplots/table/col sep=comma}
\pgfplotstabletypeset{\data}
\pgfplotstablefilter[c unequal {}]{\data}{\newdata}
\pgfplotstabletypeset{\newdata}
\begin{tikzpicture}
  \begin{axis}
    \addplot table [x=a,y=b]{\newdata};
  \end{axis}
\end{tikzpicture}
\end{document}

And here's the output:

enter image description here

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.