I am trying to plot the following data with a curve fitting via pgfplots.
It seems linear regression is not suitable for my case. So I would prefer to have exponential or polynomial curve fitting on these data. How can I implement it?
Below is the current code:
% arara: pdflatex: { shell: yes }
\documentclass[border=1mm, png]{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\begin{filecontents*}{myData.dat}
X Y
2 275.68
3 1175.26
4 1351.60
5 1485.57
6 1583.30
7 1861.28
8 2095.39
9 2574.54
10 2841.74
11 2914.16
12 3965.12
13 3787.68
14 5294.83
21 10504.49
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{%
,width=10cm
,legend style={font=\footnotesize}
}
\begin{axis}[%
,xlabel=Numbers $N$ in \si{\gram\per\liter}
,ylabel=Ratio
,ymin=0
,xmin=0
,scaled y ticks=base 10:0
,legend cell align = left
,legend pos = north west
]
\addplot[only marks] table {mydata.dat};
\addlegendentry{Ratio of \emph{tfml} to \emph{gGN}}
\addplot+[no markers,red] table [y={create col/linear regression={y=Y}}]{myData.dat};
\addlegendentry{%
Linear trend $(y=\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb})$} %
\end{axis}
\end{tikzpicture}
\end{document}
Which yields:


gnuplotinpgfplots? I guess, this kind of calculation needs some higher tool. Personally, I would recommend to calculate the curve you need via sageTeX and to plot it afterwards. – LaRiFaRi Jun 26 '14 at 11:41pgfplotsautomatically. – LCFactorization Jun 26 '14 at 11:47pgfplotsandpgfplotstable. Please have a look! I didn't check. – LaRiFaRi Jun 26 '14 at 11:57$-$is a minus sign. Therefore I would not set the unit of your ratio in math-mode. (As units should not be set in square brackets (ISO & SI) and a "ratio" has the unit 1 by definition, I would leave it away completely.). 2. please make you code minimal. You just needsiunitx,pgfplots, andpgfplotstablefor this example. – LaRiFaRi Jun 26 '14 at 12:04pgfplotsmyself. thank you for suggestions. Are you interested in editing my post so that I can learn from you? – LCFactorization Jun 26 '14 at 12:14gnuplotin the background. See Non-linear curve fitting with gnuplot (this may be a duplicate of that question). – Jake Jun 26 '14 at 12:35arXiv.org. The TeXlive system inarXiv.orgmay not supportgnuplot(but I am not very sure). – LCFactorization Jun 26 '14 at 12:47\pgfplotsset{compat=1.1}doesn't work for me; I have to set it as at least1.3 - 1.5or there will be compiling error. – LCFactorization Jun 26 '14 at 13:02gnuplotwould solve my problem easily. thank you! – LCFactorization Jun 26 '14 at 13:191.10is what I wrote. Maybe you have to update your packages. You can add\listfilesin your preamble in order to read your current version in the.log-file. Just set thecompat-number to your version. However, 1.10 is the most recent: http://www.ctan.org/pkg/pgfplots – LaRiFaRi Jun 26 '14 at 13:20TeXLiveofarXiv.org. Thank you. I now realized this is a version number; I checked and found that only 1.3, 1.4 and 1.5 work for me now. – LCFactorization Jun 26 '14 at 13:26