7

I'm having trouble with a quite complex CSV file to plot with pgfplots.

My CSV data looks like this:

01: Some;header;information;;
02: Some;header;information;;
03: Some;header;information;;
>>> more header lines going here
42: Column1;Column2;Column3;Column4;Column5
43: 0,1;230;23455;1234,3;0,01
44: 0,2;723;23457;1234,2;0,45
45: 0,3;20;1235;953345,1;0,87
46: 0,4;1233;1684;1234,0;0,99
>>> more lines with data to plot here

The line indicators are just for better comprehension and are not content of the CSV file! So to describe the file, the first 41 lines contain some header information. Line 42 contains the column names to plot. Line 43 and up contains all the data, usualy floating point data in this format: 1234,123456. All columns are seperated by semicolon (;).

What I need

is to specify some arbitrary columns to plot. One to use for x-axis and one for y-axis.

What I have tried so far (without any success):

\documentclass[parskip=half,final,12pt,abstracton,oneside,a4paper,bibliography=totocnumbered,numbers=noenddot,listof=totoc]{scrreprt}
% includes for graph plots
\usepackage{pgfplots}
\pgfplotsset{width=0.8\textwidth, compat=newest} 

\begin{document}

\begin{figure}[h] %% TEST GRAPH {{{
  \centering
  \begin{tikzpicture}
    \begin{axis}[
        legend pos=north west,
        xlabel={Some x-value \[$n$\]},
        ylabel={Some y-value in [\%]},
      ]
      \addplot +[restrict expr to domain={\coordindex}{42:97}]  
      table[x=Column1, y=Column5, col sep=semicolon,ignore chars={\,}]
      {graphs/Complex_CSV_Data.csv};
      \addlegendentry{Some Data}
    \end{axis}
  \end{tikzpicture}
  \caption{Some Gprah}
  \label{fig:Some Graph}
\end{figure} % }}}

\end{document}

LaTeX keeps telling me the following:

Package pgfplots Warning: Table      
'graphs/Complex_CSV_Data.csv' has non-unique column name ''. 
Only the first occurence can be accessed  via column names. on input line 16.

...

! Package pgfplots Error: Sorry, could not retrieve column 'Column1' from table
'\\pgfplotstableread@filename@@table@name '. Please check spelling (or introdu
ce name aliases)..

...

! Package pgfplots Error: Sorry, the requested column number '' in table 'graph
s/Complex_CSV_Data.csv' does not exist!? Please verify you used the correct
index 0 <= i < N..

[EDIT] Solution:

See solution of Christian Feuersänger. To get the solution working I had to update my pgfplots package. It turned out, that my pgfplots package was outdated due to TeX Live 2013 Distribution. I solved the issue by hitting the following lines (as sudo) into console:

sudo tlmgr update --self
sudo tlmgr update pgfplots

1 Answer 1

4

What you need is skip first n and /pgf/number format/read comma as period:

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.13}

\begin{document}

  \begin{tikzpicture}
    \begin{axis}
      \addplot  
      table[x=Column1, y=Column5, col sep=semicolon,skip first n=5,/pgf/number format/read comma as period]
      {
Some;header;information;;
Some;header;information;;
Some;header;information;;
>>> more header lines going here
Column1;Column2;Column3;Column4;Column5
0,1;230;23455;1234,3;0,01
0,2;723;23457;1234,2;0,45
0,3;20;1235;953345,1;0,87
0,4;1233;1684;1234,0;0,99
      };
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

The key skip first n=<value> will skip over the first rows. The key read comma as period reconfigures the math pathers to read a comma as period. Note that you should consider modifying your routines which generates the CSV as I would expect that this last key can cause difficulties (for example, you cannot use it inside of math expressions).

4
  • Thanks, I didn't knew about this keys. Anyway I still get Package PGF Math Error: Could not parse input '0,000090' as a floating point number, sorry. The unreadable part was near ',000090'. Looks that I'm still missing something. I'm not allowed to rewrite my CSV routine, hence I have to support Excel on german Windows machines too.
    – Marschal
    Commented Aug 16, 2016 at 20:15
  • 1
    Do you also get failures for my minimal example? I am wondering if the software version on your installation does not contain the feature use comma as period. Can you also watch out for failures about use comma as period not being known? Commented Aug 16, 2016 at 20:19
  • You were right, it's telling me ! Package pgfkeys Error: I do not know the key '/pgf/number format/read comma a s period' and I am going to ignore it. Perhaps you misspelled it.
    – Marschal
    Commented Aug 16, 2016 at 20:22
  • It turned out that I was on TeX Live 2013 Distribution. I had to update my tlmgr with sudo tlmgr update --self first after I could update pgfplots with sudo tlmgr update pgfplots. Now everything works as expected. Thanks!
    – Marschal
    Commented Aug 16, 2016 at 20:36

You must log in to answer this question.

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