1

enter image description here

What do I have to do, if I want to have a 'gap' or a word e.g. 'zero' in a cell, if it's value is equal to 0?

preproc/expr={##1==0 ? "111" : "##1"} works but something like preproc/expr={##1==0 ? "{}" : "##1"} or preproc/expr={##1==0 ? "zero" : "##1"} does not work.

\documentclass[border=2pt, varwidth]{standalone}
\usepackage{pgfplotstable}

\begin{document}
\pgfplotstableread{
1    1 
2    {}
3    0 
4    4
5    0
6    5
7    6
}\test

The Table:  \pgfplotstabletypeset[]{\test} \\

Actual: \pgfplotstabletypeset[
%string type,
columns/1/.style={
% Works fine
preproc/expr={##1==0 ? "111" : "##1"},
% Does not work:
%preproc/expr={##1==0 ? "{}" : "##1"},
%preproc/expr={##1==0 ? "zero" : "##1"},
},
]{\test} 
%
Target 1: \begin{tabular}{r r} 
1  &  1           \\
2  &  {}           \\
3  &  {}           \\ 
4  &  4           \\
5  &  {}           \\
6  &  5           \\
7  &  6           \\
\end{tabular}
%
Target 2: \begin{tabular}{r r} 
1  &  1           \\
2  &  {}           \\
3  &  zero           \\ 
4  &  4           \\
5  &  zero           \\
6  &  5           \\
7  &  6           \\
\end{tabular}

\end{document}

1 Answer 1

4

This will print "missing", but not change the data. The key here is [string type], since the default is to assume numbers. Note that pgfplots ignores missing data.

\documentclass[border=2pt, varwidth]{standalone}
\usepackage{pgfplotstable}
\usepackage{pgfplots}

\begin{document}
\pgfplotstableread[header=false]{
1    1
2    {}
3    0
4    4
5    0
6    5
7    6
}\test

The Table:  \pgfplotstabletypeset[string type,
  every head row/.style={output empty row},
  columns/1/.style={string replace={}{missing}}
  ]{\test} \\

\begin{tikzpicture}
  \begin{axis}
  \addplot table[x=0,y=1]{\test};
  \end{axis}
\end{tikzpicture}

\end{document}
2
  • Ah ok, I understand. I need string replace={0}{} - very good!
    – cis
    Commented Oct 16, 2018 at 22:24
  • I guess I didn't understand what you wanted, but glad it worked out anyway. Commented Oct 17, 2018 at 0:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .