elmariachi wrote:I prefer the looks of Tickz/pgf but I can't be very picky
Those plots look nice. But as far as I know
pgfplots doesn't support the function of plotting a linear regression.
PSTricks has the capability to plot linear regression by LSM (Least Square Method). The
gnuplottex package lets you embed
GnuPlot graphics very easy, provided that this program is installed and can be found. Consider the following example.
Code: Select all
\begin{filecontents*}{datapoints.dat}
0.57 0.018
1.03 0.027
1.85 0.089
3.33 0.208
6.00 0.444
\end{filecontents*}
\documentclass[11pt,a4paper]{article}
\usepackage{fixltx2e}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage[centering,includeheadfoot,margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage[miktex]{gnuplottex}
\usepackage{units}
\usepackage{pstricks-add}
\begin{document}
\begin{figure}[!ht]
\centering
\small
\readdata{\data}{datapoints.dat}
\psset{llx=-1cm,lly=-1cm,urx=1mm,ury=1mm}
\psset{xAxisLabel={Concentration \unitfrac{mg}{l}},xAxisLabelPos={3,-0.05}}
\psset{yAxisLabel={Absorbence},yAxisLabelPos={-0.6,0.25}}
% \psframebox[linestyle=dashed,linewidth=0.4pt]{
\begin{psgraph}[Dy=0.05,subticks=5,ticksize=0pt 4pt](0,0)(6,0.45){10.5cm}{7.5cm}
\psaxes[Dy=0.05,subticks=5,labels=none,ticksize=-4pt 0](6,0.45)(0,0)(6,0.45)
\listplot[linecolor=blue,plotstyle=dots]{\data}
\listplot[linecolor=red,plotstyle=LSM,xStart=0.57,xEnd=6]{\data}
\end{psgraph}
% }
\caption{Data plot with \texttt{PSTricks}}\label{fig:dataplot-pstricks}
\end{figure}
\begin{figure}[!ht]
\centering
\begin{gnuplot}[terminal=post,terminaloptions=eps enhanced color]
set key left reverse
set xlabel 'Concentration mg/l'
set ylabel 'Absorbence'
f(x)=a*x+b
fit f(x) 'datapoints.dat' via a,b
plot 'datapoints.dat' t 'Data' , f(x) t 'Fit'
\end{gnuplot}
\caption{Data plot with \texttt{GNUplot}}\label{fig:dataplot-gnuplot}
\end{figure}
\end{document}
There are three important points you have take into account.
- Code using PSTricks (PostScript Tricks) can only be compiled with latex (not pdflatex) via DVI to PS and then be converted to PDF (i. e. with Ghostscript).
- When using the MiKTeX system, you have to add the miktex option for the gnuplottex package (see code above). For other LaTeX systems you can omit that option.
- Depending on your system, you have to call latex with the command line argument --enable-write18 (MiKTeX) or -shell-escape (Web2C, i. e. TeX Live 2008). This is for the case that you use the gnuplottex method to call GnuPlot as an external program.
If you decide to use the version with
gnuplottex, you can find the parameters for the fit function in the file
fit.log which is produced by
GnuPlot. Further enhancements to the plot itself can be found in the manual of
GnuPlot. For more information about the used packages refer to their documentations. These can be found on
CTAN.
Best regards and welcome to the board
Thorsten¹