1

I want to create the following image in TikZ/PGFplots.enter image description here

Questions such as this are a good start, but I am not clear how to modify them to include row labels. A straightforward addition of rows, such as below, only gives an error.

\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 https://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=0.8,textcolor=-mapped color!80!black},
    /pgfplots/colormap/greenyellow,
    /pgf/number format/sci,row sep=crcr,
]{
    \phantom{A} a   b   c   d\\
    a 5e-1    8e-1    4.4e-2  1e-3  \\   
    b 0.050   -0.300  -0.200  -0.100 \\
    c -0.20   0.1 0.100   0.200\\
    d 0.005   0.300   0.40    0.800\\
    d 0.8 0.030   0.050   0.70\\
}
\end{document}
mac389
  • 753
  • 1
    Your code is not compilable in its present form, would you consider adding a compilable snippet? – Raaja_is_at_topanswers.xyz Apr 03 '19 at 11:44
  • 1
    You could use a different approach as e.g. shown at https://tex.stackexchange.com/a/406444/95441 – Stefan Pinnow Apr 03 '19 at 11:57
  • Wouldn't you be better off if you used a matrix plot for that? See section ** 4.6.12 Image (Matrix) Plots** of the pgfplots manual. –  Apr 03 '19 at 14:18
  • @StefanPinnow the approach you suggested solved my problem. How can we close this question saying "It already has a solution here"? – mac389 Apr 03 '19 at 15:21

0 Answers0