0

This is my first question on Stack Exchange, and I am trying to create a heatmap with a header in LaTeX. I want to add a header (horizontal axes) that contains \backslash{Perplexity}{Learning Rate} and a vertical axes that provides more information about the table. My code is as follows:

\newcommand*{\MinNumber}{0.0}%
\newcommand*{\MidNumber}{0.5} %
\newcommand*{\MaxNumber}{1.0}%


%Apply the gradient macro
\newcommand{\ApplyGradient}[1]{%
        \ifdim #1 pt > \MidNumber pt
            \pgfmathsetmacro{\PercentColor}{max(min(100.0*(#1 - \MidNumber)/(\MaxNumber-\MidNumber),100.0),0.00)} %
            \hspace{-0.33em}\colorbox{green!\PercentColor!yellow}{#1}
        \else
            \pgfmathsetmacro{\PercentColor}{max(min(100.0*(\MidNumber - #1)/(\MidNumber-\MinNumber),100.0),0.00)} %
            \hspace{-0.33em}\colorbox{red!\PercentColor!yellow}{#1}
        \fi
}

\newcolumntype{R}{>{\collectcell\ApplyGradient}c<{\endcollectcell}}
\renewcommand{\arraystretch}{0}
\setlength{\fboxsep}{3mm} % box size
\setlength{\tabcolsep}{0pt}


\begin{table}[H]
\begin{tabular}{*{11}{R}}
    % \backslashbox{Perplexity}{Learn Late} 10 & 25 & 50 & 75 & 100 & 125 & 
%         150 & 175 & 200 & 225 & 250 \\

 0.76& 0.75& 0.76& 0.73& 0.75& 0.73& 0.74& 0.75& 0.74& 0.75&0.74\\
0.74& 0.73& 0.74& 0.72& 0.73& 0.73& 0.72& 0.74& 0.73& 0.75& 0.73\\
 0.74& 0.75& 0.75& 0.74& 0.73& 0.72& 0.74& 0.75& 0.76& 0.75& 0.74\\
0.75& 0.73& 0.74& 0.74& 0.72& 0.72& 0.72& 0.76& 0.74& 0.71& 0.75\\
0.77& 0.76& 0.73& 0.75& 0.76& 0.75& 0.73& 0.73& 0.75& 0.73& 0.73\\
0.76& 0.77& 0.73& 0.75& 0.74& 0.76& 0.74& 0.74& 0.75& 0.72& 0.73\\
 0.76& 0.78& 0.74& 0.75& 0.73& 0.75& 0.72& 0.75& 0.76& 0.73& 0.78\\
0.76& 0.79& 0.81& 0.75& 0.74& 0.74& 0.71& 0.75& 0.74& 0.71& 0.75\\
 0.74& 0.73& 0.78& 0.76& 0.75& 0.71& 0.74& 0.78& 0.76& 0.77& 0.81\\
0.79& 0.79& 0.79& 0.74& 0.76& 0.74& 0.80& 0.71& 0.75& 0.77& 0.76\\
 0.73& 0.75& 0.78& 0.76& 0.76& 0.74& 0.75& 0.75& 0.73& 0.76& 0.77\\
[![\end{tabular}
\caption{Conditional Probability Modification Trustworthiness}
\label{trust_cp_caffe}
\end{table}][1]][1]

Most of this LaTeX code were from this link

jGaboardi
  • 502
  • Glad that marmot figured out what you wanted! In the future, more people will be able to help you if you give a minimal document that compiles and a picture or detailed description of the desired output. – Davislor May 31 '19 at 23:15

1 Answers1

2

All you need to do is to use \multicolumn to tell LaTeX that these are not R type cells. Note also that slahsbox is deprecated. Do not use urgent on this site, please.

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{collcell}
\usepackage{diagbox}
\usepackage{rotating}

 %The min, mid and max values
\newcommand*{\MinNumber}{0.71}%
\newcommand*{\MidNumber}{0.76} %
\newcommand*{\MaxNumber}{0.81}%

%Apply the gradient macro
\newcommand{\ApplyGradient}[1]{%
        \ifdim #1 pt > \MidNumber pt
            \pgfmathsetmacro{\PercentColor}{max(min(100.0*(#1 - \MidNumber)/(\MaxNumber-\MidNumber),100.0),0.00)} %
            \hspace{-0.33em}\colorbox{green!\PercentColor!yellow}{#1}
        \else
            \pgfmathsetmacro{\PercentColor}{max(min(100.0*(\MidNumber - #1)/(\MidNumber-\MinNumber),100.0),0.00)} %
            \hspace{-0.33em}\colorbox{red!\PercentColor!yellow}{#1}
        \fi
}

\newcolumntype{R}{>{\collectcell\ApplyGradient}c<{\endcollectcell}}
\renewcommand{\arraystretch}{0}
\setlength{\fboxsep}{3mm} % box size
\setlength{\tabcolsep}{0pt}

\begin{document}
   \begin{sidewaystable}
        \begin{center}
            \begin{tabular}{c*{11}{R}}
            \diagbox[width=7.5em]{Perplexity}{Learn Late} & \multicolumn{1}{c}{10} & \multicolumn{1}{c}{25} &
            \multicolumn{1}{c}{50} & \multicolumn{1}{c}{75} &
            \multicolumn{1}{c}{100} & \multicolumn{1}{c}{125} &
            \multicolumn{1}{c}{150} & \multicolumn{1}{c}{175} &
            \multicolumn{1}{c}{200} & \multicolumn{1}{c}{225} &
            \multicolumn{1}{c}{250} \\[1em]
     rodent &0.76& 0.75& 0.76& 0.73& 0.75& 0.73& 0.74& 0.75& 0.74& 0.75&0.74\\
     rodent &0.74& 0.73& 0.74& 0.72& 0.73& 0.73& 0.72& 0.74& 0.73& 0.75& 0.73\\
     rodent & 0.74& 0.75& 0.75& 0.74& 0.73& 0.72& 0.74& 0.75& 0.76& 0.75& 0.74\\
     rodent &0.75& 0.73& 0.74& 0.74& 0.72& 0.72& 0.72& 0.76& 0.74& 0.71& 0.75\\
     rodent &0.77& 0.76& 0.73& 0.75& 0.76& 0.75& 0.73& 0.73& 0.75& 0.73& 0.73\\
     rodent &0.76& 0.77& 0.73& 0.75& 0.74& 0.76& 0.74& 0.74& 0.75& 0.72& 0.73\\
     rodent & 0.76& 0.78& 0.74& 0.75& 0.73& 0.75& 0.72& 0.75& 0.76& 0.73& 0.78\\
     rodent &0.76& 0.79& 0.81& 0.75& 0.74& 0.74& 0.71& 0.75& 0.74& 0.71& 0.75\\
     rodent & 0.74& 0.73& 0.78& 0.76& 0.75& 0.71& 0.74& 0.78& 0.76& 0.77& 0.81\\
     rodent &0.79& 0.79& 0.79& 0.74& 0.76& 0.74& 0.80& 0.71& 0.75& 0.77& 0.76\\
     rodent & 0.73& 0.75& 0.78& 0.76& 0.76& 0.74& 0.75& 0.75& 0.73& 0.76& 0.77\\
            \end{tabular}
        \end{center}
    \end{sidewaystable}
\end{document}

enter image description here