创建带有标题的热图表...紧急吗?

创建带有标题的热图表...紧急吗?

这是我在 Stack Exchange 上的第一个问题,我正在尝试用 LaTeX 创建带有标题的热图。我想添加一个包含标题(水平轴)\backslash{Perplexity}{Learning Rate}和一个垂直轴,以提供有关表格的更多信息。我的代码如下:

\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]

大部分 LaTeX 代码均来自此关联

答案1

您需要做的就是使用 来\multicolumn告诉 LaTeX 这些不是R类型单元格。另请注意,slahsbox 已弃用。请不要在此网站上使用 urgent。

\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}

在此处输入图片描述

相关内容