1

I have a heatmap table and would like to have the titles of the lines and columns respectively vertically to the left and horizontally on top of the table (see the first table of the MWE) but when I do that, I've found no way of resetting the styles of the second column like I can do the first in the second table.

I've tried calling it by name as every answer I found when looking up seems to indicate but it doesn't seem to work.

MWE:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{multirow}

\pgfplotsset{compat=1.16}

\begin{filecontents*}{test.csv}
empty  ,title , 1           , 2           , 3           , 4           , 5            
       ,1     , 93.10344828 , 97.64705882 , 99.0990991  , 97.89473684 , 91.78082192    
       ,2     , 76.72413793 , 80          , 84.68468468 , 95.78947368 , 76.02739726    
       ,3     , 91.37931034 , 80          , 95.4954955  , 86.31578947 , 97.26027397    
       ,4     , 78.44827586 , 89.41176471 , 93.24324324 , 93.68421053 , 89.7260274
\end{filecontents*}

\begin{filecontents*}{test2.csv}
title , 1           , 2           , 3           , 4           , 5            
1     , 93.10344828 , 97.64705882 , 99.0990991  , 97.89473684 , 91.78082192    
2     , 76.72413793 , 80          , 84.68468468 , 95.78947368 , 76.02739726    
3     , 91.37931034 , 80          , 95.4954955  , 86.31578947 , 97.26027397    
4     , 78.44827586 , 89.41176471 , 93.24324324 , 93.68421053 , 89.7260274
\end{filecontents*}



%%%%%%%%% Heatmap configuration, not my work %%%%%%%%%%%%%%%%%%%%
\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[%
        col sep=comma,
        %Heatmap stuff
         color cells={min=50,max=100,textcolor=black},
         /pgfplots/colormap={redyellowgreen}{rgb255=(255,0,0) color=(yellow) rgb255=(0,255,0)},
        /pgf/number format/fixed,
        /pgf/number format/precision=1,
        %Titles and lines
        every head row/.style={
                                before row={&&\multicolumn{5}{c}{\textbf{top}} \\ \cmidrule(lr){3-7}}, 
                                after row/.add ={    \cmidrule(lr){2-7}
                                                    \multirow{4}{*}{\rotatebox{90}{left}}
                                                }%
                              },
        every last row/.style={after row=\cmidrule[\heavyrulewidth](lr){2-7}},
        %should remove the heatmapping from the titles column
        columns/title/.style={column name=,reset styles,string type,column type={l}},%
        every first column/.style={column name=,reset styles,string type,column type={l}}%
    ]{test.csv}

    \bigskip

    \pgfplotstabletypeset[%
        col sep=comma,
        %Heatmap stuff
        color cells={min=50,max=100,textcolor=black},
        /pgfplots/colormap={redyellowgreen}{rgb255=(255,0,0) color=(yellow) rgb255=(0,255,0)},
        /pgf/number format/fixed,
        /pgf/number format/precision=1,
        %Titles and lines
        every head row/.style={
                                before row={&\multicolumn{5}{c}{\textbf{top}} \\ \cmidrule(lr){2-6}}, 
                                after row/.add ={    \midrule
                                                    %The multirow merges with the first column if uncommented
                                                    %\multirow{4}{*}{\rotatebox{90}{left}}
                                                }%
                              },
        every last row/.style={after row=\toprule},
        %
        %removes the heatmapping from the titles column
        every first column/.style={column name=,reset styles,string type,column type={l}}%
    ]{test2.csv}
\end{document}
1

Ok so thanks to this post : Customizing first column for each row in pgfplotstable and a lot of experimenting, I found out that having whitespace in the first line of the table breaks the ability to reference columns through

columns/<name>/.style=<...>

Removing those solves everything.

Hope this'll be useful to someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.