如何在 pgfplots 中有一个空的列标签

如何在 pgfplots 中有一个空的列标签

我使用 pgfplots 创建了以下热图:

在此处输入图片描述

目前我需要 来x进行编译。如果没有它,我会得到一个错误,引用 下面的 MH 值x

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

对于表格中的其他地方,条目为空是可以的,但这里不行。我该如何删除它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}

答案1

在行中

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

你告诉 TeX 行标题位于名为 的列中x。当 TeX 看不到它时,它会发出抱怨。让我们将列重命名为\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
}

结果:

在此处输入图片描述

相关内容