PGFPLOTS
PGFPLOTS works in combination with TikZ. It serves the purpose of adding plots. Mainly giving facilities to create very customized axis and read of data points inlined or in external files.
In general we think as a plot in a document as a separate part. It is regarded as a figure that we somehow include in the main document, and by tradition it has some arbitrary format independent of that in the document. Moreover due to usual limitations of plotting programs we don't dare to include complicated symbols or formulas in plots. They can't typeset formulas or text properly, but LaTeX could in principle.
PGFPLOT allow to add plots with an exquisite level of sophistication and at the same time keep all the typesetting capabilities. Let alone the capacity of giving the plot the same formatting as the rest of the document, including font type and bibliographical references.
In order to keep the tutorial short and simple I will concentrate in PGFPLOTS as a replacement for the good GNUplot.
Basics
To start using the library, just add this line to the header of a LaTeX document:
\usepackage{pgfplots}
Every plot is part of a tikzpicture (this allows to combine TikZ and PGFPLOTS seamlessly). The main object in PGFPLOTS is the axis environment.
\begin{tikzpicture} %every plot is part of a tikzpicture
\begin{axis}
... plots are defined here ...
\end{axis}
\begin{tikzpicture}
Plotting data from a file
PGFPLOTS has the ability to read data from a file (just as GNUPlot).
\begin{tikzpicture} %every plot is part of a tikzpicture
\begin{axis}
\addplot table[x index=0, y index=1] {datafile.dat};
\end{axis}
\end{tikzpicture}
Plots the 2nd column vs 1st column in a file with data in rows and columns. Indices start at 0 for numbering columns. In gnuplot the equivalent would be
plot 'datafile.dat' u 1:2