
\begingroup
\tikzset{external/figure name/.add={}{brewer_}}%
    \tikzset{
%        font=\scriptsize,
        matrix style/.style={
            font=\tiny,
            every matrix/.append style={
                matrix anchor=north,
                inner ysep=0pt,
%                fill=red!10,
                ampersand replacement=\&,
                matrix of nodes,
                nodes={
                    anchor=south,
                    minimum size=2mm,
                },
                row 1/.style={
                    inner sep=0pt,
                },
                column 1/.style={
                    inner ysep=0pt,
                    anchor=base east,
                },
                row 2 column 1/.style={
                    every node/.append style={
                        font=\bfseries\scriptsize,
%                        font=\bfseries\tiny,
                        draw,
                    },
                },
                row sep=0pt,
                column sep=0pt,
            },
        },
    }


% =============================================================================
%\def\MATRIXseq#1{%
\NewDocumentCommand{\MATRIXseq}{sm}{{%
\tikzset{/tikz/external/export=true}%
\newcommand*\scheme{#2}%
\pgfmanualpdflabel{colormap/\scheme-3}{}%
\pgfmanualpdflabel{colormap/\scheme-4}{}%
\pgfmanualpdflabel{colormap/\scheme-5}{}%
\pgfmanualpdflabel{colormap/\scheme-6}{}%
\pgfmanualpdflabel{colormap/\scheme-7}{}%
\pgfmanualpdflabel{colormap/\scheme-8}{}%
\pgfmanualpdflabel{colormap/\scheme-9}{}%
\pgfmanualpdflabel{colormap/\scheme}{}%
\foreach \x in {A,...,M} {\pgfmanualpdflabel{\scheme-\x}{}}%
\tikzsetnextfilename{brewer-seq-#2}%
\begin{tikzpicture}[
    matrix style,
]
    % instantiate all colormaps for \scheme:
    \pgfplotsset{
        colormap/\scheme-3,
        colormap/\scheme-4,
        colormap/\scheme-5,
        colormap/\scheme-6,
        colormap/\scheme-7,
        colormap/\scheme-8,
        colormap/\scheme-9,
        colormap/\scheme,
    }%
    %
    % directly access the correct color:
    % #1 is one of A,B,...,M
    \def\C##1{\node [fill=\scheme-##1] {};}%
    % in case the color should be white, also draw a black frame
    \def\D##1{\node [draw=black,fill=\scheme-##1] {};}%
    %
    % indirectly access the correct color
    % #1 is an index into the colormap, 0,1,...,13
    % #2 is the number of colors in the colormap (qualifies which colormap to use)
    % This is redundant, but it allows us to verify that the colormaps
    % work as intended without typos:
    \newcommand*\CC[2]{\node [/pgfplots/index of colormap=##1 of \scheme-##2, fill] {};}%
    % in case the color should be white, also draw a black frame
    \newcommand*\DD[2]{\node [/pgfplots/index of colormap=##1 of \scheme-##2, fill, draw=black] {};}%
    %
    % define a colorbar that has the same size as a row of colors in the matrix
    \newcommand*\CM{%
        \node[inner sep=0pt,xshift=-3.5pt,overlay,anchor=south west]{%
\IfBooleanTF{#1}{%
            \pgfmathparse{14*2mm + 16*\pgflinewidth + 1.0pt}%
}{%
            \pgfmathparse{14*2mm + 15*\pgflinewidth + 1.1pt}%
}
            \let\width=\pgfmathresult
            \pgfplotscolormaptoshadingspec{\scheme}{\width pt}\result
            \def\tempb{\pgfdeclarehorizontalshading{tempshading}{2mm}}%
            \expandafter\tempb\expandafter{\result}%
            \pgfuseshading{tempshading}%
        };
    }%
    \matrix {
\IfBooleanTF{#1}{%
                \& A         \& B         \& C         \& D         \& E         \& F         \& G         \& H         \& I         \& J         \& K         \& L         \& M         \\
        \scheme \& \D{A}     \& \C{B}     \& \C{C}     \& \C{D}     \& \C{E}     \& \C{F}     \& \C{G}     \& \C{H}     \& \C{I}     \& \C{J}     \& \C{K}     \& \C{L}     \& \C{M}     \\
        3       \&           \&           \& \CC{0}{3} \&           \&           \& \CC{1}{3} \&           \&           \& \CC{2}{3} \&           \&           \&           \&           \\
        4       \&           \& \CC{0}{4} \&           \&           \& \CC{1}{4} \&           \& \CC{2}{4} \&           \&           \& \CC{3}{4} \&           \&           \&           \\
        5       \&           \& \CC{0}{5} \&           \&           \& \CC{1}{5} \&           \& \CC{2}{5} \&           \& \CC{3}{5} \&           \& \CC{4}{5} \&           \&           \\
        6       \&           \& \CC{0}{6} \&           \& \CC{1}{6} \&           \& \CC{2}{6} \& \CC{3}{6} \&           \& \CC{4}{6} \&           \& \CC{5}{6} \&           \&           \\
        7       \&           \& \CC{0}{7} \&           \& \CC{1}{7} \&           \& \CC{2}{7} \& \CC{3}{7} \& \CC{4}{7} \&           \& \CC{5}{7} \&           \& \CC{6}{7} \&           \\
        8       \& \DD{0}{8} \&           \& \CC{1}{8} \& \CC{2}{8} \&           \& \CC{3}{8} \& \CC{4}{8} \& \CC{5}{8} \&           \& \CC{6}{8} \&           \& \CC{7}{8} \&           \\
        9       \& \DD{0}{9} \&           \& \CC{1}{9} \& \CC{2}{9} \&           \& \CC{3}{9} \& \CC{4}{9} \& \CC{5}{9} \&           \& \CC{6}{9} \& \CC{7}{9} \&           \& \CC{8}{9} \\
        CM      \& \CM       \&           \&           \&           \&           \&           \&           \&           \&           \&           \&           \&           \&           \\
%                \& A         \& B         \& C         \& D         \& E         \& F         \& G         \& H         \& I         \& J         \& K         \& L         \& M         \\
%                \& \D{A}     \& \C{B}     \& \C{C}     \& \C{D}     \& \C{E}     \& \C{F}     \& \C{G}     \& \C{H}     \& \C{I}     \& \C{J}     \& \C{K}     \& \C{L}     \& \C{M}     \\
%                \&           \&           \& \CC{0}{3} \&           \&           \& \CC{1}{3} \&           \&           \& \CC{2}{3} \&           \&           \&           \&           \\
%                \&           \& \CC{0}{4} \&           \&           \& \CC{1}{4} \&           \& \CC{2}{4} \&           \&           \& \CC{3}{4} \&           \&           \&           \\
%                \&           \& \CC{0}{5} \&           \&           \& \CC{1}{5} \&           \& \CC{2}{5} \&           \& \CC{3}{5} \&           \& \CC{4}{5} \&           \&           \\
%                \&           \& \CC{0}{6} \&           \& \CC{1}{6} \&           \& \CC{2}{6} \& \CC{3}{6} \&           \& \CC{4}{6} \&           \& \CC{5}{6} \&           \&           \\
%                \&           \& \CC{0}{7} \&           \& \CC{1}{7} \&           \& \CC{2}{7} \& \CC{3}{7} \& \CC{4}{7} \&           \& \CC{5}{7} \&           \& \CC{6}{7} \&           \\
%                \& \DD{0}{8} \&           \& \CC{1}{8} \& \CC{2}{8} \&           \& \CC{3}{8} \& \CC{4}{8} \& \CC{5}{8} \&           \& \CC{6}{8} \&           \& \CC{7}{8} \&           \\
%                \& \DD{0}{9} \&           \& \CC{1}{9} \& \CC{2}{9} \&           \& \CC{3}{9} \& \CC{4}{9} \& \CC{5}{9} \&           \& \CC{6}{9} \& \CC{7}{9} \&           \& \CC{8}{9} \\
}{%
                \& A         \& B         \& C         \& D         \& E         \& F         \& G         \& H         \& I         \& J         \& K         \& L         \& M         \\
        \scheme \& \C{A}     \& \C{B}     \& \C{C}     \& \C{D}     \& \C{E}     \& \C{F}     \& \C{G}     \& \C{H}     \& \C{I}     \& \C{J}     \& \C{K}     \& \C{L}     \& \C{M}     \\
        3       \&           \&           \& \CC{0}{3} \&           \&           \& \CC{1}{3} \&           \&           \& \CC{2}{3} \&           \&           \&           \&           \\
        4       \&           \& \CC{0}{4} \&           \&           \& \CC{1}{4} \&           \& \CC{2}{4} \&           \&           \& \CC{3}{4} \&           \&           \&           \\
        5       \&           \& \CC{0}{5} \&           \&           \& \CC{1}{5} \&           \& \CC{2}{5} \&           \& \CC{3}{5} \&           \& \CC{4}{5} \&           \&           \\
        6       \&           \& \CC{0}{6} \&           \& \CC{1}{6} \&           \& \CC{2}{6} \& \CC{3}{6} \&           \& \CC{4}{6} \&           \& \CC{5}{6} \&           \&           \\
        7       \&           \& \CC{0}{7} \&           \& \CC{1}{7} \&           \& \CC{2}{7} \& \CC{3}{7} \& \CC{4}{7} \&           \& \CC{5}{7} \&           \& \CC{6}{7} \&           \\
        8       \& \CC{0}{8} \&           \& \CC{1}{8} \& \CC{2}{8} \&           \& \CC{3}{8} \& \CC{4}{8} \& \CC{5}{8} \&           \& \CC{6}{8} \&           \& \CC{7}{8} \&           \\
        9       \& \CC{0}{9} \&           \& \CC{1}{9} \& \CC{2}{9} \&           \& \CC{3}{9} \& \CC{4}{9} \& \CC{5}{9} \&           \& \CC{6}{9} \& \CC{7}{9} \&           \& \CC{8}{9} \\
        CM      \& \CM       \&           \&           \&           \&           \&           \&           \&           \&           \&           \&           \&           \&           \\
%                \& A         \& B         \& C         \& D         \& E         \& F         \& G         \& H         \& I         \& J         \& K         \& L         \& M         \\
%                \& \C{A}     \& \C{B}     \& \C{C}     \& \C{D}     \& \C{E}     \& \C{F}     \& \C{G}     \& \C{H}     \& \C{I}     \& \C{J}     \& \C{K}     \& \C{L}     \& \C{M}     \\
%                \&           \&           \& \CC{0}{3} \&           \&           \& \CC{1}{3} \&           \&           \& \CC{2}{3} \&           \&           \&           \&           \\
%                \&           \& \CC{0}{4} \&           \&           \& \CC{1}{4} \&           \& \CC{2}{4} \&           \&           \& \CC{3}{4} \&           \&           \&           \\
%                \&           \& \CC{0}{5} \&           \&           \& \CC{1}{5} \&           \& \CC{2}{5} \&           \& \CC{3}{5} \&           \& \CC{4}{5} \&           \&           \\
%                \&           \& \CC{0}{6} \&           \& \CC{1}{6} \&           \& \CC{2}{6} \& \CC{3}{6} \&           \& \CC{4}{6} \&           \& \CC{5}{6} \&           \&           \\
%                \&           \& \CC{0}{7} \&           \& \CC{1}{7} \&           \& \CC{2}{7} \& \CC{3}{7} \& \CC{4}{7} \&           \& \CC{5}{7} \&           \& \CC{6}{7} \&           \\
%                \& \CC{0}{8} \&           \& \CC{1}{8} \& \CC{2}{8} \&           \& \CC{3}{8} \& \CC{4}{8} \& \CC{5}{8} \&           \& \CC{6}{8} \&           \& \CC{7}{8} \&           \\
%                \& \CC{0}{9} \&           \& \CC{1}{9} \& \CC{2}{9} \&           \& \CC{3}{9} \& \CC{4}{9} \& \CC{5}{9} \&           \& \CC{6}{9} \& \CC{7}{9} \&           \& \CC{8}{9} \\
}
    };
\end{tikzpicture}%
}}

\NewDocumentCommand{\MATRIXdiv}{sm}{{%
\newcommand*\scheme{#2}%
\tikzset{/tikz/external/export=true}%
\pgfmanualpdflabel{colormap/\scheme-3}{}%
\pgfmanualpdflabel{colormap/\scheme-4}{}%
\pgfmanualpdflabel{colormap/\scheme-5}{}%
\pgfmanualpdflabel{colormap/\scheme-6}{}%
\pgfmanualpdflabel{colormap/\scheme-7}{}%
\pgfmanualpdflabel{colormap/\scheme-8}{}%
\pgfmanualpdflabel{colormap/\scheme-9}{}%
\pgfmanualpdflabel{colormap/\scheme-10}{}%
\pgfmanualpdflabel{colormap/\scheme-11}{}%
\pgfmanualpdflabel{colormap/\scheme}{}%
\foreach \x in {A,...,O} {\pgfmanualpdflabel{\scheme-\x}{}}%
\tikzsetnextfilename{brewer-div-#2}%
\begin{tikzpicture}[
    matrix style,
]
    % instantiate all colormaps for \scheme:
    \pgfplotsset{
        colormap/\scheme-3,
        colormap/\scheme-4,
        colormap/\scheme-5,
        colormap/\scheme-6,
        colormap/\scheme-7,
        colormap/\scheme-8,
        colormap/\scheme-9,
        colormap/\scheme-10,
        colormap/\scheme-11,
        colormap/\scheme,
    }%
    %
    % directly access the correct color:
    % #1 is one of A,B,...,M
    \def\C##1{\node [fill=\scheme-##1] {};}%
    % in case the color should be white, also draw a black frame
    \def\D##1{\node [draw=black,fill=\scheme-##1] {};}%
    %
    % indirectly access the correct color
    % #1 is an index into the colormap, 0,1,...,13
    % #2 is the number of colors in the colormap (qualifies which colormap to use)
    % This is redundant, but it allows us to verify that the colormaps
    % work as intended without typos:
    \newcommand*\CC[2]{\node [/pgfplots/index of colormap=##1 of \scheme-##2, fill] {};}%
    % in case the color should be white, also draw a black frame
    \newcommand*\DD[2]{\node [/pgfplots/index of colormap=##1 of \scheme-##2, fill, draw=black] {};}%
    %
    % define a colorbar that has the same size as a row of colors in the matrix
    \newcommand*\CM{%
        \node[inner sep=0pt,xshift=-3.5pt,overlay,anchor=south west]{%
\IfBooleanTF{#1}{%
            \pgfmathparse{16*2mm + 18*\pgflinewidth + 2.3pt}%
}{%
            \pgfmathparse{16*2mm + 17*\pgflinewidth + 2.3pt}%
}%
            \let\width=\pgfmathresult
            \pgfplotscolormaptoshadingspec{\scheme}{\width pt}\result
            \def\tempb{\pgfdeclarehorizontalshading{tempshading}{2mm}}%
            \expandafter\tempb\expandafter{\result}%
            \pgfuseshading{tempshading}%
        };
    }%
    \matrix {
\IfBooleanTF{#1}{%
                \& A          \& B          \& C         \& D          \& E         \& F          \& G          \& H          \& I          \& J          \& K         \& L          \& M         \& N          \& O           \\
        \scheme \& \C{A}      \& \C{B}      \& \C{C}     \& \C{D}      \& \C{E}     \& \C{F}      \& \C{G}      \& \D{H}      \& \C{I}      \& \C{J}      \& \C{K}     \& \C{L}      \& \C{M}     \& \C{N}      \& \C{O}       \\
        3       \&            \&            \&           \&            \& \CC{0}{3} \&            \&            \& \DD{1}{3}  \&            \&            \& \CC{2}{3} \&            \&           \&            \&             \\
        4       \&            \&            \& \CC{0}{4} \&            \&           \& \CC{1}{4}  \&            \&            \&            \& \CC{2}{4}  \&           \&            \& \CC{3}{4} \&            \&             \\
        5       \&            \&            \& \CC{0}{5} \&            \&           \& \CC{1}{5}  \&            \& \DD{2}{5}  \&            \& \CC{3}{5}  \&           \&            \& \CC{4}{5} \&            \&             \\
        6       \&            \& \CC{0}{6}  \&           \&            \& \CC{1}{7} \&            \& \CC{2}{6}  \&            \& \CC{3}{6}  \&            \& \CC{4}{6} \&            \&           \& \CC{5}{6}  \&             \\
        7       \&            \& \CC{0}{7}  \&           \&            \& \CC{1}{7} \&            \& \CC{2}{7}  \& \DD{3}{7}  \& \CC{4}{7}  \&            \& \CC{5}{7} \&            \&           \& \CC{6}{7}  \&             \\
        8       \&            \& \CC{0}{8}  \&           \& \CC{1}{8}  \&           \& \CC{2}{8}  \& \CC{3}{8}  \&            \& \CC{4}{8}  \& \CC{5}{8}  \&           \& \CC{6}{8}  \&           \& \CC{7}{8}  \&             \\
        9       \&            \& \CC{0}{9}  \&           \& \CC{1}{9}  \&           \& \CC{2}{9}  \& \CC{3}{9}  \& \DD{4}{9}  \& \CC{5}{9}  \& \CC{6}{9}  \&           \& \CC{7}{9}  \&           \& \CC{8}{9}  \&             \\
        10      \& \CC{0}{10} \& \CC{1}{10} \&           \& \CC{2}{10} \&           \& \CC{3}{10} \& \CC{4}{10} \&            \& \CC{5}{10} \& \CC{6}{10} \&           \& \CC{7}{10} \&           \& \CC{8}{10} \& \CC{9}{10}  \\
        11      \& \CC{0}{11} \& \CC{1}{11} \&           \& \CC{2}{11} \&           \& \CC{3}{11} \& \CC{4}{11} \& \DD{5}{11} \& \CC{6}{11} \& \CC{7}{11} \&           \& \CC{8}{11} \&           \& \CC{9}{11} \& \CC{10}{11} \\
        CM      \& \CM        \&            \&           \&            \&           \&            \&            \&            \&            \&            \&           \&            \&           \&            \&             \\
}{%
                \& A          \& B          \& C         \& D          \& E         \& F          \& G          \& H          \& I          \& J          \& K         \& L          \& M         \& N          \& O           \\
        \scheme \& \C{A}      \& \C{B}      \& \C{C}     \& \C{D}      \& \C{E}     \& \C{F}      \& \C{G}      \& \C{H}      \& \C{I}      \& \C{J}      \& \C{K}     \& \C{L}      \& \C{M}     \& \C{N}      \& \C{O}       \\
        3       \&            \&            \&           \&            \& \CC{0}{3} \&            \&            \& \CC{1}{3}  \&            \&            \& \CC{2}{3} \&            \&           \&            \&             \\
        4       \&            \&            \& \CC{0}{4} \&            \&           \& \CC{1}{4}  \&            \&            \&            \& \CC{2}{4}  \&           \&            \& \CC{3}{4} \&            \&             \\
        5       \&            \&            \& \CC{0}{5} \&            \&           \& \CC{1}{5}  \&            \& \CC{2}{5}  \&            \& \CC{3}{5}  \&           \&            \& \CC{4}{5} \&            \&             \\
        6       \&            \& \CC{0}{6}  \&           \&            \& \CC{1}{7} \&            \& \CC{2}{6}  \&            \& \CC{3}{6}  \&            \& \CC{4}{6} \&            \&           \& \CC{5}{6}  \&             \\
        7       \&            \& \CC{0}{7}  \&           \&            \& \CC{1}{7} \&            \& \CC{2}{7}  \& \CC{3}{7}  \& \CC{4}{7}  \&            \& \CC{5}{7} \&            \&           \& \CC{6}{7}  \&             \\
        8       \&            \& \CC{0}{8}  \&           \& \CC{1}{8}  \&           \& \CC{2}{8}  \& \CC{3}{8}  \&            \& \CC{4}{8}  \& \CC{5}{8}  \&           \& \CC{6}{8}  \&           \& \CC{7}{8}  \&             \\
        9       \&            \& \CC{0}{9}  \&           \& \CC{1}{9}  \&           \& \CC{2}{9}  \& \CC{3}{9}  \& \CC{4}{9}  \& \CC{5}{9}  \& \CC{6}{9}  \&           \& \CC{7}{9}  \&           \& \CC{8}{9}  \&             \\
        10      \& \CC{0}{10} \& \CC{1}{10} \&           \& \CC{2}{10} \&           \& \CC{3}{10} \& \CC{4}{10} \&            \& \CC{5}{10} \& \CC{6}{10} \&           \& \CC{7}{10} \&           \& \CC{8}{10} \& \CC{9}{10}  \\
        11      \& \CC{0}{11} \& \CC{1}{11} \&           \& \CC{2}{11} \&           \& \CC{3}{11} \& \CC{4}{11} \& \CC{5}{11} \& \CC{6}{11} \& \CC{7}{11} \&           \& \CC{8}{11} \&           \& \CC{9}{11} \& \CC{10}{11} \\
        CM      \& \CM        \&            \&           \&            \&           \&            \&            \&            \&            \&            \&           \&            \&           \&            \&             \\
}
    };
\end{tikzpicture}%
}}

\NewDocumentCommand{\MATRIXqual}{mmO{0}}{{%
\tikzset{/tikz/external/export=true}%
\newcommand*\scheme{#2}%
\pgfmanualpdflabel{colormap/\scheme-3}{}%
\pgfmanualpdflabel{colormap/\scheme-4}{}%
\pgfmanualpdflabel{colormap/\scheme-5}{}%
\pgfmanualpdflabel{colormap/\scheme-6}{}%
\pgfmanualpdflabel{colormap/\scheme-7}{}%
\pgfmanualpdflabel{colormap/\scheme-8}{}%
\ifnum#1>8
\pgfmanualpdflabel{colormap/\scheme-9}{}%
\ifnum#1>9
\pgfmanualpdflabel{colormap/\scheme-10}{}%
\pgfmanualpdflabel{colormap/\scheme-11}{}%
\pgfmanualpdflabel{colormap/\scheme-12}{}%
\fi
\fi
\pgfmanualpdflabel{colormap/\scheme}{}%
\tikzsetnextfilename{brewer-qualit-#2}%
\begin{tikzpicture}[
    baseline,
    matrix style,
]
    \newcommand*\classes{#1}%
    % instantiate all colormaps for \scheme:
    \pgfplotsset{
        colormap/\scheme-3,
        colormap/\scheme-4,
        colormap/\scheme-5,
        colormap/\scheme-6,
        colormap/\scheme-7,
        colormap/\scheme-8,
    }
\foreach \x in {A,...,H} {\pgfmanualpdflabel{\scheme-\x}{}}%
\ifnum\classes>8
\foreach \x in {I} {\pgfmanualpdflabel{\scheme-\x}{}}%
    \pgfplotsset{
        colormap/\scheme-9,
    }
\fi
\ifnum\classes=12
\foreach \x in {J,...,L} {\pgfmanualpdflabel{\scheme-\x}{}}%
    \pgfplotsset{
        colormap/\scheme-10,
        colormap/\scheme-11,
        colormap/\scheme-12,
    }
\fi
    \pgfplotsset{
        colormap/\scheme,
    }%
    %
    \newcommand*\EmptyRows{#3}

    % directly access the correct color:
    % #1 is one of A,B,...,M
    \def\C##1{\node [fill=\scheme-##1] {};}
    %
    % indirectly access the correct color
    % #1 is an index into the colormap, 0,1,...,13
    % #2 is the number of colors in the colormap (qualifies which colormap to use)
    % This is redundant, but it allows us to verify that the colormaps
    % work as intended without typos:
    \newcommand*\CC[2]{\node [/pgfplots/index of colormap=##1 of \scheme-##2, fill] {};}
    %
    % define dummy node to just produce space
    \newcommand*\Dummy{\node {};}
%    % define a colorbar that has the same size as a row of colors in the matrix
%\ifnum\classes=8
%    \newcommand*\CM{%
%        \node[inner sep=0pt,xshift=-3.5pt,overlay,anchor=south west]{%
%                \pgfmathparse{8*2mm + 8pt}%
%            \let\width=\pgfmathresult%
%            \pgfplotscolormaptoshadingspec{\scheme}{\width pt}\result%
%            \def\tempb{\pgfdeclarehorizontalshading{tempshading}{2mm}}%
%            \expandafter\tempb\expandafter{\result}%
%            \pgfuseshading{tempshading}%
%        };
%    }
%\else\ifnum\classes=9
%    \newcommand*\CM{%
%        \node[inner sep=0pt,xshift=-3.5pt,overlay,anchor=south west]{%
%                \pgfmathparse{9*2mm + 10*\pgflinewidth + 2.3pt}%
%            \let\width=\pgfmathresult%
%            \pgfplotscolormaptoshadingspec{\scheme}{\width pt}\result%
%            \def\tempb{\pgfdeclarehorizontalshading{tempshading}{2mm}}%
%            \expandafter\tempb\expandafter{\result}%
%            \pgfuseshading{tempshading}%
%        };
%    }
%\else\ifnum\classes=12
%    \newcommand*\CM{%
%        \node[inner sep=0pt,xshift=-3.5pt,overlay,anchor=south west]{%
%                \pgfmathparse{12*2mm + 13*\pgflinewidth + 2.3pt}%
%            \let\width=\pgfmathresult%
%            \pgfplotscolormaptoshadingspec{\scheme}{\width pt}\result%
%            \def\tempb{\pgfdeclarehorizontalshading{tempshading}{2mm}}%
%            \expandafter\tempb\expandafter{\result}%
%            \pgfuseshading{tempshading}%
%        };
%    }
%\fi\fi\fi
\ifnum\classes=8
    \matrix (m) {
                \& A          \& B          \& C          \& D          \& E          \& F          \& G          \& H          \\
        \scheme \& \C{A}      \& \C{B}      \& \C{C}      \& \C{D}      \& \C{E}      \& \C{F}      \& \C{G}      \& \C{H}      \\
        3       \& \CC{0}{3}  \& \CC{1}{3}  \& \CC{2}{3}  \&            \&            \&            \&            \&            \\
        4       \& \CC{0}{4}  \& \CC{1}{4}  \& \CC{2}{4}  \& \CC{3}{4}  \&            \&            \&            \&            \\
        5       \& \CC{0}{5}  \& \CC{1}{5}  \& \CC{2}{5}  \& \CC{3}{5}  \& \CC{4}{5}  \&            \&            \&            \\
        6       \& \CC{0}{6}  \& \CC{1}{6}  \& \CC{2}{6}  \& \CC{3}{6}  \& \CC{4}{6}  \& \CC{5}{6}  \&            \&            \\
        7       \& \CC{0}{7}  \& \CC{1}{7}  \& \CC{2}{7}  \& \CC{3}{7}  \& \CC{4}{7}  \& \CC{5}{7}  \& \CC{6}{7}  \&            \\
        8       \& \CC{0}{8}  \& \CC{1}{8}  \& \CC{2}{8}  \& \CC{3}{8}  \& \CC{4}{8}  \& \CC{5}{8}  \& \CC{6}{8}  \& \CC{7}{8}  \& \Dummy \& \Dummy \& \Dummy \& \Dummy \\
%%%%%        CM      \& \CM        \&            \&            \&            \&            \&            \&            \&            \\
    };
\else\ifnum\classes=9
    \matrix (m) {
                \& A          \& B          \& C          \& D          \& E          \& F          \& G          \& H          \& I         \\
        \scheme \& \C{A}      \& \C{B}      \& \C{C}      \& \C{D}      \& \C{E}      \& \C{F}      \& \C{G}      \& \C{H}      \& \C{I}     \\
        3       \& \CC{0}{3}  \& \CC{1}{3}  \& \CC{2}{3}  \&            \&            \&            \&            \&            \&           \\
        4       \& \CC{0}{4}  \& \CC{1}{4}  \& \CC{2}{4}  \& \CC{3}{4}  \&            \&            \&            \&            \&           \\
        5       \& \CC{0}{5}  \& \CC{1}{5}  \& \CC{2}{5}  \& \CC{3}{5}  \& \CC{4}{5}  \&            \&            \&            \&           \\
        6       \& \CC{0}{6}  \& \CC{1}{6}  \& \CC{2}{6}  \& \CC{3}{6}  \& \CC{4}{6}  \& \CC{5}{6}  \&            \&            \&           \\
        7       \& \CC{0}{7}  \& \CC{1}{7}  \& \CC{2}{7}  \& \CC{3}{7}  \& \CC{4}{7}  \& \CC{5}{7}  \& \CC{6}{7}  \&            \&           \\
        8       \& \CC{0}{8}  \& \CC{1}{8}  \& \CC{2}{8}  \& \CC{3}{8}  \& \CC{4}{8}  \& \CC{5}{8}  \& \CC{6}{8}  \& \CC{7}{8}  \&           \\
        9       \& \CC{0}{9}  \& \CC{1}{9}  \& \CC{2}{9}  \& \CC{3}{9}  \& \CC{4}{9}  \& \CC{5}{9}  \& \CC{6}{9}  \& \CC{7}{9}  \& \CC{8}{9} \& \Dummy \& \Dummy \& \Dummy \\
%%%%%        CM      \& \CM        \&            \&            \&            \&            \&            \&            \&            \&           \\
    };
\else\ifnum\classes=12
    \matrix (m) {
                \& A          \& B          \& C          \& D          \& E          \& F          \& G          \& H          \& I          \& J          \& K           \& L           \\
        \scheme \& \C{A}      \& \C{B}      \& \C{C}      \& \C{D}      \& \C{E}      \& \C{F}      \& \C{G}      \& \C{H}      \& \C{I}      \& \C{J}      \& \C{K}       \& \C{L}       \\
        3       \& \CC{0}{3}  \& \CC{1}{3}  \& \CC{2}{3}  \&            \&            \&            \&            \&            \&            \&            \&             \&             \\
        4       \& \CC{0}{4}  \& \CC{1}{4}  \& \CC{2}{4}  \& \CC{3}{4}  \&            \&            \&            \&            \&            \&            \&             \&             \\
        5       \& \CC{0}{5}  \& \CC{1}{5}  \& \CC{2}{5}  \& \CC{3}{5}  \& \CC{4}{5}  \&            \&            \&            \&            \&            \&             \&             \\
        6       \& \CC{0}{6}  \& \CC{1}{6}  \& \CC{2}{6}  \& \CC{3}{6}  \& \CC{4}{6}  \& \CC{5}{6}  \&            \&            \&            \&            \&             \&             \\
        7       \& \CC{0}{7}  \& \CC{1}{7}  \& \CC{2}{7}  \& \CC{3}{7}  \& \CC{4}{7}  \& \CC{5}{7}  \& \CC{6}{7}  \&            \&            \&            \&             \&             \\
        8       \& \CC{0}{8}  \& \CC{1}{8}  \& \CC{2}{8}  \& \CC{3}{8}  \& \CC{4}{8}  \& \CC{5}{8}  \& \CC{6}{8}  \& \CC{7}{8}  \&            \&            \&             \&             \\
        9       \& \CC{0}{9}  \& \CC{1}{9}  \& \CC{2}{9}  \& \CC{3}{9}  \& \CC{4}{9}  \& \CC{5}{9}  \& \CC{6}{9}  \& \CC{7}{9}  \& \CC{8}{9}  \&            \&             \&             \\
        10      \& \CC{0}{10} \& \CC{1}{10} \& \CC{2}{10} \& \CC{3}{10} \& \CC{4}{10} \& \CC{5}{10} \& \CC{6}{10} \& \CC{7}{10} \& \CC{8}{10} \& \CC{9}{10} \&             \&             \\
        11      \& \CC{0}{11} \& \CC{1}{11} \& \CC{2}{11} \& \CC{3}{11} \& \CC{4}{11} \& \CC{5}{11} \& \CC{6}{11} \& \CC{7}{11} \& \CC{8}{11} \& \CC{9}{11} \& \CC{10}{11} \&             \\
        12      \& \CC{0}{12} \& \CC{1}{12} \& \CC{2}{12} \& \CC{3}{12} \& \CC{4}{12} \& \CC{5}{12} \& \CC{6}{12} \& \CC{7}{12} \& \CC{8}{12} \& \CC{9}{12} \& \CC{10}{12} \& \CC{11}{12} \\
%%%%%        CM      \& \CM        \&            \&            \&            \&            \&            \&            \&            \&            \&            \&             \&             \\
    };
\fi\fi\fi

% insert space as fake empty rows
\ifnum\EmptyRows>0
    \path node [below=\EmptyRows*2mm of m,anchor=south] {};
\fi

\end{tikzpicture}%
}}

\section{ColorBrewer}
\def\pgfplotsmanualcurlibrary{colormaps}

{\emph{An extension by Vincent A.\ Traag and Stefan Pinnow}}

\begin{pgfplotslibrary}{colorbrewer}

This library brings the color schemes created by Cynthia Brewer published at
\url{http://colorbrewer2.org/} to PGFPlots. These where originally designed for
cartography needs, but are also used in other kind of data visualization in the
mean time. The ColorBrewer schemes are divided into the types
%
\begin{description}
    \item[sequential] for ordered data progressing from low to high,
    \item[diverging] to highlight changes from a mean value, and
    \item[qualitative] where colors have no special order.
\end{description}
%
They can consist of up to 12 different data classes, i.e.\@ colors, per scheme
and are provided as color maps as well as as cycle lists.

{%
\centering

\pgfplotsset{
    brewer example/.style={
        small,
        title style={font=\normalfont},
    }
}%
\renewcommand{\arraystretch}{2}%
\tikzset{/tikz/external/export=true}%
\begin{tabular}{cc}
\begin{tikzpicture}[baseline]
    \begin{axis}[brewer example, hide axis,title={Diverging \texttt{colormap/PiYG-11}},colormap/PiYG-11,colorbar left]
        \addplot3[surf,
            domain=0:360,samples=40]
                {sin(x)*sin(y)};
    \end{axis}
\end{tikzpicture}
&
% ----- example in section 4.3 on page 43 -----
\tikzset{/tikz/external/export=true}%
\begin{tikzpicture}[baseline]
    % --- changed by Mo-Gul ---
    \begin{axis}[
        brewer example,
        hide axis,
        view={60}{30},
        title={Sequential \texttt{colormap/PuBu-9}},
        colormap/PuBu-9,
        colorbar right,
        clip bounding box=default tikz,
    ]
    % -------------------------
        \addplot3[
            surf,shader=flat,
            samples=20,
            domain=-1:0,y domain=0:2*pi,
            z buffer=sort
        ] (
            { sqrt(1-x^2) * cos(deg(y)) },
            { sqrt(1-x^2) * sin(deg(y)) },
            x
        );
    \end{axis}
\end{tikzpicture}%
% ---------------------------------------------
\\
% ----- second last example in section 4.6.9 on page 159 -----
% Preamble: \pgfplotsset{width=7cm,compat=1.13}
\tikzset{/tikz/external/export=true}%
\begin{tikzpicture}[baseline]
    % --- changed by Mo-Gul ---
    \begin{axis}[
        brewer example,
        hide axis,
        view={60}{30},
        title={Diverging \texttt{colormap/RdGy-11}},
        colormap/RdGy-11,
        colorbar left,
        clip bounding box=default tikz,
    ]
    % -------------------------
        \addplot3 [
            mesh,z buffer=sort,
            scatter,only marks,scatter src=z,
            samples=30,domain=-1:1,y domain=0:2*pi,
        ] (
            { sqrt(1-x^2) * cos(deg(y)) },
            { sqrt(1-x^2) * sin(deg(y)) },
            x
        );
    \end{axis}
\end{tikzpicture}
&
\begin{tikzpicture}[baseline]
    \begin{axis}[
        brewer example,
        hide axis,
        title={Sequential \texttt{colormap/YlOrBr}},
        colormap/YlOrBr,
        colorbar right,
        clip bounding box=default tikz,
    ]
    \addplot3[surf,samples=9,domain=0:1]
        {(1-abs(2*(x-0.5))) * (1-abs(2*(y-0.5)))};
    %\addlegendentry{$\phi_x \phi_y$}
    %\addplot3+[ultra thick] coordinates {(0,0,0) (0.5,0,1) (1,0,0)};
    %\addlegendentry{$\phi_x $}
    %\addplot3+[ultra thick] coordinates {(1,0,0) (1,0.5,1) (1,1,0)};
    %\addlegendentry{$\phi_y $}
    \end{axis}
\end{tikzpicture}
\\
%
% ------------------------------------------------------------
%
% ----- first example in section 4.7.4 on page 180 -----
% Preamble: \pgfplotsset{width=7cm,compat=1.13}
\begin{tikzpicture}[baseline]
\begin{loglogaxis}[
    brewer example,
    legend pos=south west,
    xlabel=\textsc{Dof},
    ylabel=$L_2$ Error,
    title={Qualitative \texttt{cycle list/Set1-5}},
    cycle list/Set1-5,
    hide axis,
    thick,
    legend style={draw=none},
    cycle multiindex* list={
        mark list*\nextlist
        Set1-5\nextlist
    },
        clip bounding box=default tikz,
    % -----------------------
]
\addplot coordinates {
    (5,8.312e-02)    (17,2.547e-02)   (49,7.407e-03)
    (129,2.102e-03)  (321,5.874e-04)  (769,1.623e-04)
    (1793,4.442e-05) (4097,1.207e-05) (9217,3.261e-06)
};
\addplot coordinates {
    (7,8.472e-02)    (31,3.044e-02)   (111,1.022e-02)
    (351,3.303e-03)  (1023,1.039e-03) (2815,3.196e-04)
    (7423,9.658e-05) (18943,2.873e-05)
    (47103,8.437e-06)
};
\addplot coordinates {
    (9,7.881e-02)     (49,3.243e-02)  (209,1.232e-02)
    (769,4.454e-03)   (2561,1.551e-03)
    (7937,5.236e-04)  (23297,1.723e-04)
    (65537,5.545e-05) (178177,1.751e-05)};
\addplot coordinates {
    (11,6.887e-02)    (71,3.177e-02) (351,1.341e-02)
    (1471,5.334e-03)  (5503,2.027e-03)
    (18943,7.415e-04) (61183,2.628e-04)
    (187903,9.063e-05) (553983,3.053e-05)};

\addplot coordinates {
    (13,5.755e-02)    (97,2.925e-02) (545,1.351e-02)
    (2561,5.842e-03)  (10625,2.397e-03)
    (40193,9.414e-04) (141569,3.564e-04)
    (471041,1.308e-04) (1496065,4.670e-05)
};
\legend{$d=2$,$d=3$,$d=4$,$d=5$,$d=6$}
\end{loglogaxis}
\end{tikzpicture}
&
% ----- example in section 4.7.7 on page 195 -----
\begin{tikzpicture}[baseline]
\pgfplotsset{
    cycle from colormap manual style/.style={
        x=3cm,y=10pt,ytick=\empty,
        colorbar style={x=,y=,ytick=\empty},
        point meta min=0,point meta max=1,
        stack plots=y,
        y dir=reverse,colorbar style={y dir=reverse},
        every axis plot/.style={line width=2pt},
        legend entries={0,...,20},
        legend pos=outer north east,
    }
}
\begin{axis}[
    % --- changed by Mo-Gul -----
    % also the text before and after that code has to be adjusted
    brewer example,
    hide axis,
    title={Diverging \texttt{cycle list/RdYlBu-4}},
    cycle list/RdYlBu-4,
    %
    cycle from colormap manual style,
    x=,y=,
    legend entries=,
        clip bounding box=default tikz,
]
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
    \addplot coordinates {(0,1) (0.5,1) (1,1)};
\end{axis}
\end{tikzpicture}\\
\end{tabular}

}%
% ------------------------------------------------


\subsection{Usage}

In the following the available schemes are presented in graphical form as
``swatches''.


\subsubsection*{Color Schemes as ``Swatches''}
\label{sec:pgfplots:brewer:usage}

A swatch is a matrix showing all available colors for a specific scheme, and
the available color compilations.

{\centering
% inspired from http://mkweb.bcgsc.ca/brewer/swatches/brewer-palettes-swatches.pdf
\tikzset{/tikz/external/export=true}%
\tikzsetnextfilename{brewer-fig-intro-GnBu}%
\begin{tikzpicture}[
    font=\scriptsize,
]
    \newcommand*\scheme{GnBu}
    % instantiate all colormaps for \scheme:
    \pgfplotsset{
        colormap/\scheme-3,
        colormap/\scheme-4,
        colormap/\scheme-5,
        colormap/\scheme-6,
        colormap/\scheme-7,
        colormap/\scheme-8,
        colormap/\scheme-9,
        colormap/\scheme,
    }%

    % directly access the correct color:
    % #1 is one of A,B,...,M
    \def\C#1{\node [fill=\scheme-#1] {};}

    % just set a label to an invisible cell
    \def\D#1{\node [draw=none] (#1) {};}

    % define a colorbar that has the same size as a row of colors in the matrix
    \newcommand*\CM{%
        \node[inner sep=0pt,xshift=-4.4pt,overlay,anchor=south west]{%
            \pgfmathparse{13*3mm + 0pt}%
            \let\width=\pgfmathresult
            \pgfplotscolormaptoshadingspec{\scheme}{\width pt}\result
            \def\tempb{\pgfdeclarehorizontalshading{tempshading}{3mm}}%
            \expandafter\tempb\expandafter{\result}%
            \pgfuseshading{tempshading}%
        };
    }

    \matrix[
        ampersand replacement=\&,
        matrix of nodes,
        nodes={
            anchor=south,
            minimum size=3mm,
        },
        row 1/.style={
            inner sep=0pt,
        },
        column 1/.style={
            inner ysep=0pt,
            anchor=base east,
        },
        row 2 column 1/.style={
            every node/.append style={
                font=\bfseries\scriptsize,
                draw,
            },
        },
        row sep=0pt,
        column sep=0pt,
    ] (m) {
                \& A     \& B     \& C     \& D     \& E     \& F     \& G     \& H     \& I     \& J     \& K     \& L     \& M     \\
        \scheme \& \C{A} \& \C{B} \& \C{C} \& \C{D} \& \C{E} \& \C{F} \& \C{G} \& \C{H} \& \C{I} \& \C{J} \& \C{K} \& \C{L} \& \node [fill=\scheme-M] (c) {}; \\
        3       \&       \&       \& \C{C} \&       \&       \& \C{F} \&       \&       \& \C{I} \&       \&       \&       \&       \\
        4       \&       \& \C{B} \&       \&       \& \C{E} \&       \& \C{G} \&       \&       \& \C{J} \&       \&       \&       \\
        5       \&       \& \C{B} \&       \&       \& \C{E} \&       \& \C{G} \&       \& \C{I} \&       \& \C{K} \&       \&       \\
        6       \&       \& \C{B} \&       \& \C{D} \&       \& \C{F} \& \C{G} \&       \& \C{I} \&       \& \C{K} \&       \&       \\
        7       \& \D{a} \& \C{B} \&       \& \C{D} \&       \& \C{F} \& \C{G} \& \C{H} \&       \& \C{J} \&       \& \C{L} \& \D{b} \\
        8       \& \C{A} \&       \& \C{C} \& \C{D} \&       \& \C{F} \& \C{G} \& \C{H} \&       \& \C{J} \&       \& \C{L} \&       \\
        9       \& \C{A} \&       \& \C{C} \& \C{D} \&       \& \C{F} \& \C{G} \& \C{H} \&       \& \C{J} \& \C{K} \&       \& \C{M} \\
        CM      \& \CM   \&       \&       \&       \&       \&       \&       \&       \&       \&       \&       \&       \& \D{CM} \\
    };

    \node [coordinate,pin={[align=center]above left:(short) \\ scheme \\ name}]
        at ([xshift=5pt] m-2-1.north west) {};
    \node [coordinate,pin={right:letters to create scheme color name}]
        at ([xshift=5pt] m-1-14) {};
    \node [coordinate,pin={right:all colors of scheme}]
        at ([xshift=5pt] c) {};
    \node [coordinate,pin={[align=center]below:numbers to create \\ (full) scheme name \\ (number of data classes)}]
        at ([xshift=0pt] m-10-1.south) {};
    \node [coordinate,pin={[align=left]right:colormap based on \\ previous row colors; \\
                                             (also) accessible by the \\ short scheme name}]
        at ([xshift=5pt] CM) {};

    \draw [red,rounded corners=2pt]
        ([xshift=-1pt] a.north west)
            rectangle
        ([xshift=+1pt] b.south east)
    ;
    \node [coordinate,pin=right:colors of scheme \texttt{GnBu-7}]
        at ([xshift=1pt] b.east) {};

\end{tikzpicture}

}%

Such swatches are read as follows:
%
\begin{enumerate}
    \item At the top left of the block you find the (short) name of the scheme.
    \item The following color blocks are the colors the scheme consists of.
    \item To get the (full) color name, combine the (short) scheme name with
        a hyphen and a letter of the first row, e.g.

        |\tikz \fill[color=GnBu-H] (0,0) rectangle (1em,2ex);|

        which results in \tikz \fill[color=GnBu-H] (0,0) rectangle
        (1em,2ex);.
    \item To get the full scheme name, which can be used as colormap or cycle
        list, combine the (short) scheme name with a hyphen and a number of
        the first column, e.g.\@ |cycle list name=GnBu-7|. \\
        The special case of using the (short) scheme name only is also
        provided and is an alias for the full scheme name with the highest
        number, e.g.\@ scheme name \texttt{GnBu} equals \texttt{GnBu-9}.
    \item The last row shows a continuous color map based on the previous row,
        that is in the example \texttt{GnBu-9}.
    \item The rest of the matrix shows the colors used in the corresponding
        scheme.
\end{enumerate}


\subsubsection*{Activating Color Schemes}

In order to activate a |colorbrewer| |colormap|, say, |BuGn-5|, you have to use
the key

    |colormap/BuGn-5|.

\noindent This will initialize and select the associated |colormap|. It will
also initialize the associated |cycle list| (but will not select it). In order
to initialize and select the |cycle list| of name |BuGn-5|, you have to use the
key

    |cycle list/BuGn-5|.

\noindent This will initialize and select the associated |cycle list|. It will
also initialize (but not select) the associated |colormap|.


Note that |cycle list|s shipped with |colorbrewer| merely consist of
\emph{colors}. However, a good |cycle list| typically also comes with markers
and perhaps line style variations. In order to combine a pure color-based
|cycle list| with markers, you should make use of the features
|cycle multi list|, |cycle multiindex list|, and |cycle multiindex* list|, for
example using
%
\begin{codeexample}[code only]
\pgfplotsset{
    % initialize Set1-5:
    cycle list/Set1-5,
    % combine it with 'mark list*':
    cycle multiindex* list={
        mark list*\nextlist
        Set1-5\nextlist
    },
}
\end{codeexample}
%
\noindent Please refer to the reference manual for |cycle multiindex* list| for
details.


\subsection{Sequential Schemes}

Sequential schemes are useful for ordered data progressing low to high.

\noindent
\begin{tabular}{rrr}
    \MATRIXseq{BuGn}   & \MATRIXseq{PuRd}   & \MATRIXseq{Blues}   \\
    \MATRIXseq{BuPu}   & \MATRIXseq{RdPu}   & \MATRIXseq{Greens}  \\
    \MATRIXseq{GnBu}   & \MATRIXseq{YlGn}   & \MATRIXseq*{Greys}  \\
    \MATRIXseq{OrRd}   & \MATRIXseq{YlGnBu} & \MATRIXseq{Oranges} \\
    \MATRIXseq{PuBu}   & \MATRIXseq{YlOrBr} & \MATRIXseq{Purples} \\
    \MATRIXseq{PuBuGn} & \MATRIXseq{YlOrRd} & \MATRIXseq{Reds}    \\
\end{tabular}


\subsection{Diverging Schemes}

Diverging schemes highlight changes from some mean value.

\noindent
\begin{tabular}{rrr}
    \MATRIXdiv{BrBG}   & \MATRIXdiv*{RdGy}   & \MATRIXdiv{RdYlBu} \\
    \MATRIXdiv{PiYG}   & \MATRIXdiv{PuOr}  & \MATRIXdiv{RdYlGn}\\
    \MATRIXdiv{PRGn}   & \MATRIXdiv{RdBu}  & \MATRIXdiv{Spectral}\\
\end{tabular}

Note that you can adopt |point meta min| and |point meta max| such that the
|colormap|'s mean value fits the data (for example by forcing
|point meta min=-2| and |point meta max=+2|).


\subsection{Qualitative Schemes}

Qualitative schemes are useful if colors have no special order, but should be
distinguishable.

\noindent
\begin{tabular}{rrr}
    \MATRIXqual{8}{Accent}    & \MATRIXqual{9}{Pastel1}[3] & \MATRIXqual{8}{Pastel2} \\
    \MATRIXqual{8}{Dark2}[1]  & \MATRIXqual{9}{Set1}       & \MATRIXqual{8}{Set2}[4]\\
    \MATRIXqual{12}{Paired}   & \MATRIXqual{12}{Set3}      & \\
\end{tabular}


\subsection{Interaction with the ColorBrewer website}

To find a scheme, e.g.\@ the above chosen \texttt{GnBu-7} on
\url{http://colorbrewer2.org/}
%
\begin{itemize}
    \item first select the ``Nature of your data'' type; in this case
        ``sequential'',
    \item then select the ``Number of data classes'', which is 7,
    \item and last select the corresponding scheme in the ``Pick a color
        scheme'' section. (This is a bit tricky, because you can only see the
        name at the top of the lower right corner, where all the colors are
        listed. When you have selected the right one you should read there
        ``7-class GnBu''. But perhaps it helps when you know that ``Gn''
        stands for green and ``Bu'' for blue, so you are searching for a
        scheme going from green to blue, which in this case is the third
        color scheme in the first row of ``Multi-hue''.)
    \item The color names, e.g.\@ \texttt{GnBu-H}, cannot be extracted from
        the page directly though, because you cannot simply count to the
        number and replace it with the corresponding letter. This
        intentionally was avoided, because then one would define the same
        color multiple times with different names, e.g.\@ \texttt{GnBu-H} 3
        times.
    \item If you should need let's say the 5th color of the scheme
        \texttt{GnBu-7} you don't have to trial and error or have a look at
        the manual. %
        \pgfplotsset{colormap/GnBu-7}%
        You can simply extract this color from the corresponding color map
        via the \verb|index of colormap| feature, e.g.

        |\tikz \fill[index of colormap={4 of GnBu-7}] (0,0) rectangle (1em,2ex);|

        which results in \tikz \fill[index of colormap={4 of GnBu-7}] (0,0)
        rectangle (1em,2ex);. Note that the index is $4$ instead of $5$
        because the index starts with $0$. Note furthermore that you have to
        invoke |\pgfplotsset{colormap/GnBu-7}| before using this key.
\end{itemize}


\subsection{External Examples}

If you want to see some examples, where Brewer has used her schemes, have a
look at \url{https://www.census.gov/population/www/cen2000/atlas/index.html}.

\end{pgfplotslibrary}

\begin{tikzlibrary}{colorbrewer}
    A library which contains just the color definitions like |GnBu-B|. Please
    refer to Section~\ref{sec:pgfplots:brewer:usage} for a list of available
    colors.
\end{tikzlibrary}
\endgroup
\endinput
