The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Tag Info

{pgfplots} is a package for creating 2D and 3D plots of mathematical functions and numerical data, using the PGF graphics framework. For questions about the inbuilt plotting functionality of TikZ/PGF, use {tikz-pgf} instead.

Questions tagged with are about the plotting package of the same name, which uses the PGF graphics framework to create 2D and 3D plots of mathematical functions or numerical data.

The package supports the creation of standard plot types such as scatter plots, line plots, bar/column plots, area plots, and mesh/surface plots, but also of more exotic ones such as comb plots or piecewise constant plots.

The coordinates for the plots can be supplied in the form of mathematical functions using the mathematical engine provided by the PGF framework, by providing coordinates directly in the document, or by reading datafiles from the file system.

Plots created with pgfplots are vector graphics and can thus be scaled without loss of quality. Titles and labels are set as normal text and thus use the same font as the rest of the document, leading to a homogeneous appearance.

A simple example, plotting the function f(x)=x3:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document} A more advanced example of a bar chart with varying bar widths (taken from the pgfplots manual):

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar interval=0.9,
x tick label as interval,
xmin=2003,xmax=2030,
ymin=0,ymax=140,
xticklabel={
$\pgfmathprintnumber{\tick}$
-- $\pgfmathprintnumber{\nexttick}$},
xtick=data,
x tick label style={
rotate=90,anchor=east,
/pgf/number format/1000 sep=}
]

coordinates
{(2003,40) (2005,100) (2006,15)
(2010,90) (2020,120) (2030,3)};
\end{axis}
\end{tikzpicture}
\end{document} An example of a 3D plot of the function f(x,y)=sin(x)*sin(y) (taken from the pgfplots manual). Note that trigonometric functions in PGF use degrees instead of radians.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis} 