我在让回归工作时遇到了麻烦。如果您不介意查看代码并指出正确的方向,我将不胜感激。我已经加载了 pgfplots 和 pgfplotstable 包。我是第一次在这里提问,如果我犯了任何礼仪上的错误,我深表歉意。
\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}
我的.csv 文件如下所示:
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
答案1
密钥col sep
需要放在table [...]
选项中,而不是\addplot [...]
选项中:
\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}