0

I use the following code to color the numbers within my table like a heatmap

\usepackage{colortbl}
\usepackage{pgfplots}
\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 https://tex.stackexchange.com/questions/12668/where-do-i-start-latex-programming/27589#27589 \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 }% }% } }

Then I use it like this:

\pgfplotstabletypeset[
color cells={min=-1,max=800},
col sep=&,  % specify the column separation character
row sep=\\, % specify the row separation character
columns/A/.style={string type} % specify the type of data in the designated column
]{
    A & B & C & D & E \\
    a & 10 & 10.1 & 100 & 11 \\
    b & 20 & 10.2 & 200 & 12 \\
    c & 30 & 10.3 & 300 & 13 \\
}

However, it expects all columns to be number, while I want to use labels for rows. It gives the following error:

Package PGF Math Error: Could not parse input 'a' as a floating point number, sorry. The unreadable part was near 'a'.. }```
Ahmad
  • 1,013

0 Answers0