1

Here is the file: data
I can't get the following code to work. Apparently adding and subtracting the rows is the problem. Am I missing something here?

 \documentclass[crop,tikz]{standalone}
    \usepackage{pgfplots}
    \usepackage{pgfplotstable}
    \usepgfplotslibrary{fillbetween}
    \begin{document}
    \begin{tikzpicture}
    \begin{axis}[
        width=\linewidth, 
        xmin = 0, xmax = 90,
        ymin = 45, ymax =65,
        xlabel= {Time[s]},
        ylabel={ST},
        error bars/y dir=both, % turn on error bars
        error bars/y explicit]
        %upper line for the interval
        \addplot[name path=upper, fill=none, draw=none] table[col sep=comma, x=pn_T, y expr=\thisrow{pn_ST} + \thisrow{pn_SD}]{data.csv}; 
        %lower line for the interval
        \addplot[name path=lower, fill=none, draw=none] table[col sep=comma, x=pn_T, y expr=\thisrow{pn_ST} - \thisrow{pn_SD}]{data.csv};
        %fill between the lines
        \addplot[green!40] fill between[of=lower and upper];
        %add the two plots 
        \addplot+[ color=blue, mark=., thin, error bars/error bar style={gray}] table[col sep=comma, x=Base_T, y=Base_ST, y error=Base_SD] {data.csv} ;
        \addplot+[ color=green,mark=., thin] table[col sep=comma, x=pn_T, y=pn_ST] {data.csv} ;     
    \end{axis}
    \end{tikzpicture}
    \end{document}

I Get the following error when I try to compile the code in my main document:

! Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ' + '). See the PGF Math package documentation for explanation. Type H for immediate help. ... l.13 ...n_ST} + \thisrow{pn_SD}]{data/tritonad.csv}; This error message was generated by an \errmessage command, so I can't give any explicit help. Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.

Mensch
  • 65,388
  • 2
    It returns a plot to me, whether it is displayed right or wrong, I am not able to say. Maybe you can be more specific about what exactly is not working the way you expect it do be? – Jasper Habicht Jul 30 '22 at 19:48
  • This is the error I get: ! Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ' + '). See the PGF Math package documentation for explanation. – BubbleFlow Aug 02 '22 at 09:55
  • Are you sure that use the very same CSV file that you link to above? It seems to me that PGF tries to find a numerical value in column pn_ST for the given row but this cell is empty. You should check in your CSV whether there are maybe rows with only empty values. – Jasper Habicht Aug 02 '22 at 10:27
  • 2
    You can add \pgfkeys{/pgf/fpu/handlers/empty number/.code={\pgfmathparse{0}}} to your preamble. This will tell PGF to handle any empty string as zero. But you should actually look into your CSV file for empty values and set them to nan (see https://tex.stackexchange.com/q/83735/47927). – Jasper Habicht Aug 02 '22 at 12:41
  • @ Jasper Habicht, I added that line to the document and it solved my problem. I can plot the data now. Thanks. – BubbleFlow Aug 02 '22 at 12:53
  • Depending on the data, \pgfkeys{/pgf/fpu/handlers/empty number/.code={\pgfmathparse{nan}}} might be more accurate. – Jasper Habicht Aug 02 '22 at 12:55

0 Answers0