1

I have a csv file named "aaa.csv" whose content is:

aa,bb,cc
1,1,1
2,2,4
3,3,9
4,4,16

I make plot with the data in this file by pgfplots. But my code fails to compile. The following message is given:

ERROR: Package pgfplots Error: Sorry, could not retrieve column 'aa' 
from table 'aaa.csv'. Please check spelling (or introduce name aliases)..

What's wrong with my code?

MWE:

\documentclass[a4paper]{article}
\usepackage{pgf,pgfplots,pgfplotstable}

\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
    xtick=data,
    xticklabels from table={aaa.csv}{aa},
    width=.9\textwidth,
    title=test,
    xlabel={$x$},
    ylabel={$y$},
    ymin=0,xmin=0,
]
\addplot [red,mark=*,] table[col sep=comma,x=bb,y=cc] {aaa.csv};
\end{axis}
\end{tikzpicture}
\end{document}

1 Answer 1

4

You need to tell the plot earlier that your data is using a comma as separator:

\documentclass[a4paper]{article}
\usepackage{pgf,pgfplots,pgfplotstable}

\pgfplotsset{compat=1.16,}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
    xtick=data,
    table/col sep=comma,
    xticklabels from table={aaa.csv}{aa},
    width=.9\textwidth,
    title=test,
    xlabel={$x$},
    ylabel={$y$},
    ymin=0,xmin=0,
]
\addplot [red,mark=*,] table[x=bb,y=cc] {aaa.csv};
\end{axis}
\end{tikzpicture}
\end{document}
1
  • There is table before col sep=comma! That's it! I once tried 'col sep=comma' but failed. Thank you very much for your suggestion!
    – lyl
    Apr 21, 2019 at 12:50

You must log in to answer this question.

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