I'm trying to create something like a confusion matrix of several classes. Thus, I want to display only the shades of the values.
I manage to do it using this:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\makeatletter
\pgfplotsset{
/pgfplots/table/omit header/.style={%
/pgfplots/table/typeset cell/.append code={%
\ifnum\c@pgfplotstable@rowindex=-1
\pgfkeyslet{/pgfplots/table/@cell content}\pgfutil@empty%
\fi
}
}
}
\makeatother
\pgfplotstableset{
color cells/.style={%
header=false,
omit header,
col sep=comma,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\cellcolor{black!##1}\pgfmathtruncatemacro\number{##1}\ifnum\number>50\color{white}\fi}
}
}
}
\begin{document}
\begin{table}\caption{Correlation or something}
\centering
\pgfplotstabletypeset[color cells]{
100,0,0,0,0,0,0
0,100,0,0,0,0,0
0,0,50,0,0,0,0
0,0,1.4,90,0,0,0
0,8,0,0,95,0,8
0,5,10,0,0,60,0
0,15,0,0,0,0,80
}
\end{table}
\end{document}
However, if the number of classes increases the table won't fit in the page. Thus, I tried to reduce its size by adding font=\tiny
to the color cells
style. However, that produces non square cells. Moreover, I will want to tune the size of the squares to accommodate several classes that may require a size smaller than that provided by the \tiny
fontsize.
\pgfplotstableset{
color cells/.style={%
font=\tiny,
header=false,
omit header,
col sep=comma,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\cellcolor{black!##1}\pgfmathtruncatemacro\number{##1}\ifnum\number>50\color{white}\fi}
}
}
}
Also, I'm not sure if changing the font is the correct approach to resize the cells, but I didn't find another way. If there is another way of altering the size of the cells, I will appreciate that information.