PGFPlots is a powerful package for creating high-quality plots and graphs in LaTeX documents. It builds upon the TikZ drawing package to provide a user-friendly interface for data visualization.
To use PGFPlots, you need to include the package in your LaTeX preamble:
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
The second line sets the compatibility level, ensuring consistent behavior across different PGFPlots versions.
A basic PGFPlots graph is created using the axis
environment within a tikzpicture
:
\begin{tikzpicture}
\begin{axis}[
xlabel={X Label},
ylabel={Y Label},
title={Plot Title}
]
\addplot coordinates {
(0, 0)
(1, 1)
(2, 4)
(3, 9)
};
\end{axis}
\end{tikzpicture}
PGFPlots supports various plot types, including:
You can customize your plots using a wide range of options. For example, to change line color and style:
\addplot[color=red, dashed, mark=*] coordinates {
(0, 0)
(1, 2)
(2, 1)
};
PGFPlots offers multiple ways to input data:
For larger datasets, using external files is recommended:
\addplot table {data.txt};
PGFPlots provides advanced features for complex visualizations:
By mastering PGFPlots, you can create professional-quality graphs that seamlessly integrate with your LaTeX documents. Whether you're working on articles, reports, or presentations, PGFPlots offers the flexibility and power to visualize your data effectively.