# Heat map

> A grid of values colored by size, with each value printed in its cell. A pgfplots example with its complete LaTeX source, ready to copy or open in TeXeR.

A pgfplots example in the TeXeR TikZ library: https://texer.org/library/pgfplots/heat-map

Package: [pgfplots](https://texer.org/library/pgfplots.md), on CTAN at https://ctan.org/pkg/pgfplots.

Tags: heat map, matrix plot, colormap

## Source

```latex
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{tikzpicture}
  \begin{axis}[
    width=9cm, height=6.5cm, enlargelimits=false,
    colormap={blues}{color=(white) color=(blue!55)}, colorbar,
    xtick={0,...,4}, xticklabels={Mon, Tue, Wed, Thu, Fri},
    ytick={0,...,3}, yticklabels={Night, Evening, Afternoon, Morning},
    tick style={draw=none},
    nodes near coords={\pgfmathprintnumber\pgfplotspointmeta},
    nodes near coords style={font=\footnotesize, anchor=center},
  ]
    \addplot[matrix plot*, mesh/cols=5, point meta=explicit] coordinates {
      (0,0) [2]  (1,0) [3]  (2,0) [1]  (3,0) [4]  (4,0) [6]

      (0,1) [14] (1,1) [12] (2,1) [15] (3,1) [18] (4,1) [25]

      (0,2) [22] (1,2) [27] (2,2) [24] (3,2) [21] (4,2) [19]

      (0,3) [31] (1,3) [29] (2,3) [35] (3,3) [28] (4,3) [17]
    };
  \end{axis}
\end{tikzpicture}
```

## As a complete document

The same example in a document that compiles on its own with pdfLaTeX:

```latex
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    width=9cm, height=6.5cm, enlargelimits=false,
    colormap={blues}{color=(white) color=(blue!55)}, colorbar,
    xtick={0,...,4}, xticklabels={Mon, Tue, Wed, Thu, Fri},
    ytick={0,...,3}, yticklabels={Night, Evening, Afternoon, Morning},
    tick style={draw=none},
    nodes near coords={\pgfmathprintnumber\pgfplotspointmeta},
    nodes near coords style={font=\footnotesize, anchor=center},
  ]
    \addplot[matrix plot*, mesh/cols=5, point meta=explicit] coordinates {
      (0,0) [2]  (1,0) [3]  (2,0) [1]  (3,0) [4]  (4,0) [6]

      (0,1) [14] (1,1) [12] (2,1) [15] (3,1) [18] (4,1) [25]

      (0,2) [22] (1,2) [27] (2,2) [24] (3,2) [21] (4,2) [19]

      (0,3) [31] (1,3) [29] (2,3) [35] (3,3) [28] (4,3) [17]
    };
  \end{axis}
\end{tikzpicture}
\end{document}
```
