4

I would like to construct a "heatmap" style table, as described in this question: Drawing heatmaps using TikZ

One way to proceed might be to modify this code by Christian Feuersänger, given as the accepted answer there: http://pgfplots.net/tikz/examples/color-maps/

Is there a simple way to modify this code to not color the first column of the table (as these are commonly labels of some kind) or in general to only color a subset of the cells?

1 Answers1

7

To not color the column having header t, you can add

columns/t/.style={reset styles}

or, for a non-numeric column:

columns/a/.style={reset styles,string type},

to the \pgfplotstabletypeset options. A complete example using one of the tables of the example linked in the question:

\documentclass[varwidth=true,border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotstableset{
    /color cells/min/.initial=0,
    /color cells/max/.initial=1000,
    /color cells/textcolor/.initial=,
    %
    % Usage: 'color cells={min=<value which is mapped to lowest color>, 
    %   max = <value which is mapped to largest>}
    color cells/.code={%
        \pgfqkeys{/color cells}{#1}%
        \pgfkeysalso{%
            postproc cell content/.code={%
                %
                \begingroup
                %
                % acquire the value before any number printer changed
                % it:
                \pgfkeysgetvalue{/pgfplots/table/@preprocessed
                  cell content}\value
                \ifx\value\empty
                    \endgroup
                \else
                \pgfmathfloatparsenumber{\value}%
                \pgfmathfloattofixed{\pgfmathresult}%
                \let\value=\pgfmathresult
                %
                % map that value:
                \pgfplotscolormapaccess
                    [\pgfkeysvalueof{/color cells/min}:\pgfkeysvalueof{/color
                      cells/max}]
                    {\value}
                    {\pgfkeysvalueof{/pgfplots/colormap name}}%
                % now, \pgfmathresult contains {<R>,<G>,<B>}
                % 
                % acquire the value AFTER any preprocessor or
                % typesetter (like number printer) worked on it:
                \pgfkeysgetvalue{/pgfplots/table/@cell content}\typesetvalue
                \pgfkeysgetvalue{/color cells/textcolor}\textcolorvalue
                %
                % tex-expansion control
                % see http://tex.stackexchange.com/questions/12668/
                \toks0=\expandafter{\typesetvalue}%
                \xdef\temp{%
                    \noexpand\pgfkeysalso{%
                        @cell content={%
                            \noexpand\cellcolor[rgb]{\pgfmathresult}%
                            \noexpand\definecolor{mapped
                              color}{rgb}{\pgfmathresult}%
                            \ifx\textcolorvalue\empty
                            \else
                                \noexpand\color{\textcolorvalue}%
                            \fi
                            \the\toks0 %
                        }%
                    }%
                }%
                \endgroup
                \temp
                \fi
            }%
        }%
    }
}
\begin{document}
\pgfplotstabletypeset[
    color cells={min=-300,max=800},
    col sep=comma,
    columns/a/.style={reset styles}
]{
    a,b,c,d
    50,-300,-200,-100
    -20,0,100,200
    5,300,40,800
    3,30,50,70
}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128