3

I found some code to asign colors to table values with PGFplotstable, but unfortunately it is only designed for tables where the topmost row is a head row (which is ignored by postproc). I also need the first column to be ignored by postproc - probably realtively simple but I just cant find how to do it.

This is the code:

\pgfplotstableset{
    color cells/.style={
        col sep=comma,
        string type,
        postproc cell content/.code={%
                \pgfkeysalso{@cell content=\rule{0cm}{2.4ex}%
                \pgfmathsetmacro\y{min(100,max(0,abs(round(##1 * 0.5))))}%
                \ifnum##1<0\edef\temp{\noexpand\cellcolor{blue!\y}}\temp\fi%
                \ifnum##1>0\edef\temp{\noexpand\cellcolor{red!\y}}\temp\fi%
                \pgfmathtruncatemacro\x\y%
                \ifnum\x>50 \color{white}\fi%
                ##1}%
                }
    }
}

\begin{table}\caption{Correlation or something}
\centering
\pgfplotstabletypeset[color cells]{
a,b,c,d
x,-300,-200,-100
y,0,100,200
z,300,40,800
}
\end{table}

(original source is: Drawing heatmaps using TikZ)

The code does not work, as the values in the first column are not numbers - i just want to ignore them, leaving those cells as they are.

0

1 Answer 1

5

Ahhh I found it, pretty simple actually: I start the tabe with the attribute 'columns/a/.style={reset styles,string type}' :

\pgfplotstabletypeset[color cells, columns/a/.style={reset styles,string type}]

Where 'a' is the name of my first column !

Hope this helps someone else ;)

1
  • Helped me, thanks! I thought one could do this by index (e.g. columns/1/.style=... but only found this: every first column/.style=... to work.
    – BadAtLaTeX
    Commented Apr 7, 2020 at 0:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .