4

I have created the following heatmap using pgfplots:

enter image description here

Currently I need the x to make it compile. Without it, I get an error referring to the MH value below the x:

! Package PGF Math Error: Could not parse input 'MH' as a floating point number, sorry. The unreadable part was near 'MH'..'

For other places in the table it's fine for the entry to be empty, but not here. How can I remove that x?

\documentclass{standalone}
\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 http://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
            }%
        }%
    }
}

\begin{document}

\pgfplotstabletypeset[%
     color cells={min=0,max=210,textcolor=black},
    %/pgfplots/colormap={orangewhiteorange}{rgb255=(255,170,0) color=(white) rgb255=(255,170,0)},
    /pgfplots/colormap/greenyellow,
    /pgf/number format/fixed,
    /pgf/number format/precision=3,
    col sep=comma,
    columns/x/.style={reset styles,string type}%
]{%%%%%%%
% fbankpitch2joint
x,MH,LH,L,H,M    
MH,0,3,15,12,32
LH,7,0,16,10,30
L,8,9,0,37,210 
H,5,10,25,0,89 
M,16,8,168,67,0
}

\end{document}
oadams
  • 143

1 Answers1

6

In the line

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

you tell TeX that row headers are in a column named x. When TeX does not see it, it complains. Let us rename the column to \space:

\pgfplotstabletypeset[%
     color cells={min=0,max=210,textcolor=black},
    %/pgfplots/colormap={orangewhiteorange}{rgb255=(255,170,0) color=(white) rgb255=(255,170,0)},
    /pgfplots/colormap/greenyellow,
    /pgf/number format/fixed,
    /pgf/number format/precision=3,
    col sep=comma,
    columns/\space/.style={reset styles,string type}%
]{%%%%%%%
% fbankpitch2joint
\space,MH,LH,L,H,M    
MH,0,3,15,12,32
LH,7,0,16,10,30
L,8,9,0,37,210 
H,5,10,25,0,89 
M,16,8,168,67,0
}

Result:

enter image description here

Boris
  • 38,129