[Tex/LaTex] Interpolation and curve fitting – Tikzpicture? Gnuplot? Pgfplot

curve fittinggnuplotpgfplotstikz-pgf

well, I am fairly new to LaTeX, but I tried my hardest do find a solution for my problem but I couldn't find a proper answer, so I hope someone here has the answer or another suggestion for me.

I would like to "smooth" my curve, but if I do so the curve will be partially negative, which is physically impossible and therefore no solution for my thesis. I have read that this happens due to the algorithm used.

Does someone know how to fix that? Is there any other way to smooth my graph maybe using another package or command?
enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage{float} 

\begin{document}


\begin{figure}[H]
\begin{center}
    \begin{tikzpicture}
    \begin{axis}[
    %title=Without legend box,
    legend style={draw=none},
    grid = major,
    %ymin=0,
    %ymax=0.000012,
    xmax=144,
    xmin=100,
    %legend columns=2,
    width=0.65\textwidth, 
    height=6.8cm,
     legend style={
    cells={anchor=east},
    legend pos=outer north east,
}]
        \pgfplotstableread{Help.txt}
        \datatable
        \addplot[smooth, no markers, color=black, line width=1.25pt] table[y = P3] from \datatable ;
        \addlegendentry{1}  ;
        \addplot[smooth, no markers, color=blue, line width=1.25pt] table[y = P4] from \datatable ;
        \addlegendentry{2}  ;

    \end{axis}
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

The data

f P3 P4 
100 0.000004 0 
102 0.000014 0 
104 0.000008 0 
106 0.000017 0 
108 0.000021 0 
110 0.000043 0 
112 0.000126 0.000005 
114 0.000347 0.000023 
116 0.0012 0.000113 
118 0.00599 0.000735 
120 0.061 0.0036 
122 0.9 0.144 
122.227 1.5 0.273 
124 0.13 0.007 
126 0.0053 0.0012 
128 0.0022 0.00043 
130 0.0003 0.0002 
132 0.000246 0.000103 
134 0.000132 0.000065 
136 0.000072 0.00004 
138 0.000045 0.000027 
140 0.000032 0.00002 
142 0.000024 0.000013 
144 0.000016 0.000011

Best Answer

Run it with xelatex:

\documentclass[pstricks,border=10pt]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{file.data}
f P3 P4 
100 0.000004 0 
102 0.000014 0 
104 0.000008 0 
106 0.000017 0 
108 0.000021 0 
110 0.000043 0 
112 0.000126 0.000005 
114 0.000347 0.000023 
116 0.0012 0.000113 
118 0.00599 0.000735 
120 0.061 0.0036 
122 0.9 0.144 
122.227 1.5 0.273 
124 0.13 0.007 
126 0.0053 0.0012 
128 0.0022 0.00043 
130 0.0003 0.0002 
132 0.000246 0.000103 
134 0.000132 0.000065 
136 0.000072 0.00004 
138 0.000045 0.000027 
140 0.000032 0.00002 
142 0.000024 0.000013 
144 0.000016 0.000011
\end{filecontents*}
\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-5mm,-10mm)(5.5,3)
\psset{yunit=2}
\psaxes[Ox=100,Dx=10,dx=1,Dy=0.5,axesstyle=frame, xticksize=-0.25 1.5,yticksize=0 5,
  subticks=5,subticksize=1,subtickcolor=black!15,labelFontSize=\scriptstyle](0,0)(0,-0.25)(5,1.5)
\readdata[ignoreLines=1]{\data}{file.data}
\pstScalePoints(1,1){100 sub 10 div }{}
\pslistplot[linecolor=blue,linewidth=1pt,plotNo=1,plotNoMax=2,plotstyle=bezier,xEnd=123]{\data}
\pslistplot[linecolor=blue,linewidth=1pt,plotNo=1,plotNoMax=2,plotstyle=curve,xStart=122.2]{\data}
\pslistplot[linecolor=red,linewidth=1pt,plotNo=2,plotNoMax=2,plotstyle=bezier,xEnd=123]{\data}
\pslistplot[linecolor=red,linewidth=1pt,plotNo=2,plotNoMax=2,plotstyle=curve,xStart=122.2]{\data}

\end{pspicture}

\end{document}

enter image description here