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:
Best Answer
This is an attempt via polynomial fit and the use of
gnuplot
. Therefore this requires one to compile the code with shell-escape enabled, andgnuplot
has to be installed on your system.Edit: The OP finds how to find the actually parameters after curve fitting. The answer is here: show fitted values which needs two lines of code
Code