The package pgfplotstable defines a key string replace* that can be used to replace strings inside a typeset table (in \pgfplotstabletypeset); for instance (quoting from the manual)

string replace*={2}{6},
col sep=&,row sep=\\]{
colA & colB & colC \\
11     & 12     & 13    \\
21     & 22     & 23    \\

Is there a way to use the same string replacement method when I am plotting the values in the table using pgfplots? For instance, I would like to write something like


1 2
3 4
4 5
5 4

\pgfplotstableread[string replace*={4}{-5}]{example.dat}\loadedtable

\addplot table[x=A,y=B] \loadedtable; % putting a string replace in this line doesn't work either.

which does not work: the table is typeset, but the numbers 4 are not replaced with -5, that is, the string replace* key seems to be ignored.

In case there is a better solution: what I am really trying to do is replacing all NaN with infinity (or a sufficiently large number) in an error bar plot: conceptually they represent the fact that the algorithm failed, so I need a full bar, not an empty one.

  • string replace is done during typesetting the data is not altered. You can save the table instead. – percusse Feb 25 '16 at 16:43
  • @percusse Thanks. What do you mean by "you can save the table instead"? – Federico Poloni Feb 25 '16 at 17:07
  • Modifying the contents is difficult. Creating new columns by copying and editing is easier. – John Kormylo Feb 25 '16 at 20:24

Do you mean something like the following?

(For details have a look at the comments in the code.)

            % you have to give the y range manually, because otherwise the range
            % will automatically be adjusted so that the error bars fit into the range
                % define the error value which should be used
                % in case the given error value is `NaN'
                % inspired by <http://tex.stackexchange.com/a/114310/95441>
                    % 3 = NaN
                    % 4 = +inf
                    % 5 = -inf

            \addplot+ [
                error bars/.cd,
                    y dir=both,y explicit,
            ] table[x=A,y=B,
                % use the above defined function `VALERR' here
                y error expr=VALERR,
            ] {
                % for simplicity I moved the table here
                A B e
                1 1 1
                2 2 NaN
                3 3 1
                4 2 inf

image showing the result of above code

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.