Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents}{testdata.csv}
  Probe      Mittelwert Standardabweichung
  well_PS         100.00       0.00
  PL-04-021_3      12.19       2.47
  Dextran         104.63       6.28
\end{filecontents}

\pgfplotstableread[col sep=space]{testdata.csv}\datatable

\begin{document}

  \begin{tikzpicture}
    \begin{axis}
      \addplot table[x=Probe,y=Mittelwert]{\datatable};
    \end{axis}
  \end{tikzpicture}
\end{document}

But I keep getting errors from pgfplotstable like

! Package pgfplots Error: Could not read table file 'testdata.csv'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try `row sep=crcr' and terminate your lines with `\\' (refer to the pgfplotstable manual for details).

What am I doing wrong? Is there a possibility to get more verbose error output?

Update

I found this link which explains how to read a string column, but I fail to read in my .csv file, although hard coded in the .tex it works.

share|improve this question
    
One point that I see is that you load the table with comma as column separator but your datafile is not comma separated. But this alone does not solve the problem. If I fix this I get a message that the first column is not a floating point number. Therefore you somehow have to tell pgfplots that the column is containing text instead of numbers. –  Benedikt Bauer Feb 6 '13 at 20:27
    
Yes, sorry this is a copy and paste error, I fixed it. I found this question, which seems to be similar, but it didn't solved my problem: tex.stackexchange.com/questions/63335/… –  Reza Feb 6 '13 at 20:35

2 Answers 2

There are two problems here: First, you're trying to use strings (the "Probe" column) as the x-coordinate. By default, PGFPlots doesn't know what to do with that (should the point for well_PS be plotted before or after Dextran?). An elegant workaround for this is to simply use the coordinate indes of each data point for its x-coordinate, and use the text from the "Probe" column just for the tick labels. You can do this by using

\addplot table[x expr=\coordindex,y=Mittelwert]{\datatable};

to plot the data, putting

xtick=data,
xticklabels from table={\datatable}{Probe}

in your axis options to set the labels.

Then we run into the second problem, however: You have underscores in your "Probe" column, which lead to a Missing $ inserted error, because by default underscores are used to start a subscript in maths mode. The easiest way to fix this is to replace the underscores in your datatable with \_:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents}{testdata.csv}
  Probe      Mittelwert Standardabweichung
  well\_PS         100.00       0.00
  PL-04-021\_3      12.19       2.47
  Dextran         104.63       6.28
\end{filecontents}

\pgfplotstableread[col sep=space]{testdata.csv}\datatable

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
            xtick=data,
            xticklabels from table={\datatable}{Probe},
        ]
     \addplot table[x expr=\coordindex,y=Mittelwert]{\datatable};
    \end{axis}
  \end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks a lot this is a very nice solution, although I don't understand why "Probe" isn't working and "Mittelwert" is. But thanks anyway! P.S is there a way to pass latex expressions without having to mask them? Because I'm getting my data from a spreadsheet and for big amount of data's this would be to much work. –  Reza Feb 7 '13 at 8:29
    
@Reza: "Mittelwert" contains numbers, so they work fine. "Probe" contains text, so PGFPlots isn't sure how to handle that in a plotting context. I'm not entirely sure how to get the underscores to work straight away, I've opened a new question (ah, I see you've seen it already). –  Jake Feb 7 '13 at 8:42

As far as I know, your problem is based on linebreaks.
The way linebreaks are induced in Linux and Windows is different. Maybe you have seen the good old \l\n in some other programming language before. Basically, Windows wants you to tell it to move to the row below and to the left, while Linux assumes - you want to go down, than you want to go left as well. It does save a little hard-disk and occasionally leads to problems.
If you define inline data like that, this can be written with the wrong line ending by TeX. I'm not sure if it helps, but maybe changing your file format and/or your \usepackage[T1]{inputenc} can do the trick. Your editor of choice will be of assistance with the file format. Just say save as to see the options.
Sorry, but it is a hard to reproduce problem.
If everything else fails you will really have to add \\ to the end of every line and add the option row sep=crcr to your pgfplotstableread.

Also, usually it is advisable not to include tables this way. Simply plot them with \addplot table [x=Probe,y=Mittelwert,col sep=space] {testdata.csv}. It is easier on TeX's limited memory.

Try to experiment a little and report back.

share|improve this answer
    
I'm using lualatex with utf8 encoding, thus it shouldn't be of any problem. Could there be problems with the underlines in the table? What do you mean with \addplot table[options]. –  Reza Feb 7 '13 at 6:43
    
Adjusted the answer accordingly, but yes: The other answer is correct. I missed to look at the contents of your table. –  user24276 Feb 7 '13 at 11:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.