3

I am having trouble getting regression to work. If you wouldn't mind just looking over the code and point me in the right direction I'd really appreciate it. I have loaded pgfplots and pgfplotstable packages.I am new to asking questions here, I apologise if I have made any errors in etiquette.

\begin{figure}
\begin{center}
\begin{tikzpicture}
  \begin{axis}[
      axis lines=left,
      width=\linewidth, % Scale the plot to \linewidth
      xlabel=$\omega ^-1$, % Set the labels
      ylabel=Limiting Current,
      x unit=\si{\radian\per\second}$^-\frac{1}{2}, % Set the respective units
      y unit=\si{\ampere},
      %xmin=-1100,
      %ymin=-0.00004,
      legend style={at={(1,0.7)},anchor=north east}
    ]
    \addplot [mark=*,color=red,only marks,col sep=comma]
    table {Data/nRDE400.csv};
    \addplot [mark=none,color=blue]
    table[y={create col/linear regression={y=column 2}},col sep=comma] {Data/nRDE400.csv};
  \end{axis}
\end{tikzpicture}
\caption{RDE studies of modified electrode in 0.5 M NaOH saturated with \ce{O2} and scan rate of 20 \si{\milli\volt\per\second}.}
\label{RDESCANS2}
\end{center}
\end{figure}

My .csv file looks like this:

column 1,column 2
0.1545,6.4721
0.1093,9.1529
0.0892,11.2100
0.0773,12.9442
0.0691,14.4720
0.0631,15.8533
  • Hi Charles, welcome to the site! In general, it's preferred to include a minimal working example instead of code snippets, i.e. a complete document (starting with \documentclass) that can be compiled without changes and that includes only the minimum code necessary to demonstrate the problem. The code I included in my answer is an example of how such a document could look in your case. – Jake Jul 21 '15 at 15:44
  • Hi Jake, thank you for the welcome. I am very excited to contribute and improve my LateX with the help of the people here. I understand what mean completely. I will be sure to post questions in the manner you have said from now on. – Charles O'Donoghue Jul 22 '15 at 7:39
2

The col sep key needs to go in the table [...] options, not the \addplot [...] options:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot [mark=*,color=red,only marks]
    table [col sep=comma] {data.csv};
    \addplot [mark=none,color=blue]
    table[y={create col/linear regression={y=column 2}},col sep=comma] {data.csv};
  \end{axis}
\end{tikzpicture}

\end{document}
| improve this answer | |
  • Hi Jake, thank you very, very much for your answer. It sorted everything out straight away. – Charles O'Donoghue Jul 22 '15 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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