[Tex/LaTex] Pgfplots plotting data from a csv file

csvpgfplotstikz-pgf

I'm trying to create a diagram with three x-axes at the bottom. I found a code which creates 3 axes but when I try to plot the data from a csv file I get an error stating:

! Package pgfkeys Error: I do not know the key '/tikz/col sep', to which you passed 'comma', and I am going to ignore it. Perhaps you misspelled it.

I have no problem plotting csv files in other settings but somehow I can't get this to work. What am I doing wrong?
Here is the file:
test.csv

Here is my code:

\begin{document}
\usepackage{pgfplots}

    \begin{tikzpicture}
        \pgfplotsset{    
        every axis x label/.style={
        at={(ticklabel* cs:1.05)},
        yshift = -7.5pt,
        anchor=west,},
        width=14cm,
        height=7cm,
        every axis y label/.style={at={(current axis.above origin)},
        anchor=north east,
        yshift = 1cm,} }
        \begin{axis}[
        scaled y ticks = false,
          y tick label style={/pgf/number format/fixed,
          /pgf/number format/1000 sep = \thinspace},
          xmin=0,xmax=3,
          xlabel={$Re$},
          ylabel={$\delta ~\text{[mm]}$},
          ymin=0, ymax=2,
          ymajorgrids=true, xmajorgrids=true,
          axis y line*=left, axis x line*=bottom]
          \addplot[color=red,smooth,thick, col sep=comma] {test.csv};
        \end{axis}
        \begin{axis}[
            xmin=0,xmax=70,%--- CF,
            hide y axis,
             axis x line*=none,
            ymin=0, ymax=2,
            xlabel={$\dot{V} ~[\text{L} / \text{h}]$},
            x label style={yshift=-0.8cm},
            x tick label style={yshift=-0.8cm}
            ]
        \addplot[color=blue,smooth,thick] coordinates { 
                  (2.28,1.09068)
            (1.67,0.97372)
            (1.11,0.832298376)
            (0.55,0.634618222)
            (0.27,0.46422) };
        \end{axis} 
          \begin{axis}[
            xmin=0,xmax=35,
            hide y axis,
            axis x line*=none,
            ymin=0, ymax=2,
            xlabel={$\dot{V}/A ~[\text{m}^3 / \text{h} \text{m}^2]$},
            x label style={yshift=-1.6cm},
            x tick label style={yshift=-1.6cm}
            ]
        \addplot[color=black,thick] coordinates { 
                  (2.28,1.09068)
            (1.67,0.97372)
            (1.11,0.832298376)
            (0.55,0.634618222)
            (0.27,0.46422) };
        \end{axis}   
    \end{tikzpicture}
\end{document}

Best Answer

This contains an answer to your question, I think, and an MWE. The answer to your question is that you should try

\addplot[color=red,smooth,thick] table[col sep=comma,header=false,x index=0,y index=1] {test.csv};

which works if your test.csv data has a format in which there is a comma separator. This is because col sep=comma is a valid option for a table, but not for a plot. Notice that I also increased xmax for that plot since with your setting the full plot gets clipped away.

To make it an MWE, I

  1. added a document class,
  2. loaded amsmath (since you are using \text),
  3. moved \usepacage{pgfplots} above \begin{document},
  4. added test.csv to the MWE via filecontents to make it easier to test.

I did not change any of the details, also because I do not really now what Re stands for. If it stands for real part, I wouldn't set it in math mode.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{test.csv}
70.4,1.012015504
52.8,0.919477106
35.2,0.803237238
17.6,0.637529818
8.8,0.506007752
\end{filecontents*}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
    \pgfplotsset{    
    every axis x label/.style={
    at={(ticklabel* cs:1.05)},
    yshift = -7.5pt,
    anchor=west,},
    width=14cm,
    height=7cm,
    every axis y label/.style={at={(current axis.above origin)},
    anchor=north east,
    yshift = 1cm,} }
    \begin{axis}[
    scaled y ticks = false,
      y tick label style={/pgf/number format/fixed,
      /pgf/number format/1000 sep = \thinspace},
      xmin=0,xmax=75,
      xlabel={$Re$},
      ylabel={$\delta ~\text{[mm]}$},
      ymin=0, ymax=2,
      ymajorgrids=true, xmajorgrids=true,
      axis y line*=left, axis x line*=bottom]
      \addplot[color=red,smooth,thick] table[col sep=comma,header=false,
      x index=0,y index=1] {test.csv};
    \end{axis}
    \begin{axis}[
        xmin=0,xmax=70,%--- CF,
        hide y axis,
         axis x line*=none,
        ymin=0, ymax=2,
        xlabel={$\dot{V} ~[\text{L} / \text{h}]$},
        x label style={yshift=-0.8cm},
        x tick label style={yshift=-0.8cm}
        ]
    \addplot[color=blue,smooth,thick] coordinates { 
              (2.28,1.09068)
        (1.67,0.97372)
        (1.11,0.832298376)
        (0.55,0.634618222)
        (0.27,0.46422) };
    \end{axis} 
      \begin{axis}[
        xmin=0,xmax=35,
        hide y axis,
        axis x line*=none,
        ymin=0, ymax=2,
        xlabel={$\dot{V}/A ~[\text{m}^3 / \text{h} \text{m}^2]$},
        x label style={yshift=-1.6cm},
        x tick label style={yshift=-1.6cm}
        ]
    \addplot[color=black,thick] coordinates { 
              (2.28,1.09068)
        (1.67,0.97372)
        (1.11,0.832298376)
        (0.55,0.634618222)
        (0.27,0.46422) };
    \end{axis}   
\end{tikzpicture}
\end{document}

enter image description here

Related Question