Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In an effort to collect knowledge that will ultimately allow me to answer this question, I am seeking a way to generate a table where numeric values are plotted as cell-filling colors. The color should represent the number.
N.B.: I am not trying to repost the question I mentioned above. Here I am asking for a way to approach merely a subset of that question.

A rendering of my MWE below:
plot as a table

So far, I have been trying to achieve this using pgfplots (inspired by this answer), but there are some drawbacks in the measuring department:
I'd have to do all the math by hand, in order to make sure all rows and columns align nicely (see MWE). Additionally, styling tick labels with alternating styles will be tough, as a PGFplot is not entirely built to do that. And on top of that, adding meta-labels in order to group tick labels (see other question) is probably going to be impossible.

In a nutshell, the approach I have so far (using PGFplots) is not ideal, since what I want is to draw a table. But then, tables don't have these powerful ways of representing numeric values as colors, a.f.a.i.k.

MWE:

\documentclass{standalone}

\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}

\begin{filecontents}{data.csv}
yitem,xitem,val
a,X,0.1
a,Z,0.3
b,Y,0.5
b,Z,0.6
c,Y,0.8
\end{filecontents}

\pgfplotstableread[col sep=comma]{data.csv}\datatable

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    xtick=data,
    ytick=data,
    unbounded coords=jump,
    symbolic x coords={X,Y,Z},
    symbolic y coords={a,b,c},
    axis line style={draw=none},
    tick style=transparent,
    y tick label style={
        inner sep=0,
        font=\tiny,
    },
    x tick label style={
        inner sep=0,
        font=\tiny,
        rotate=90,
        anchor=east,
    },
    enlarge x limits={abs=1mm},
    enlarge y limits={abs=1mm},
    x=2mm,
    y=2mm,
]
\addplot[
    mark=square*,
    mark size=1mm,
    only marks,
    scatter,
    mark options={outer sep=0},
    scatter/use mapped color={fill=mapped color,draw opacity=0},
    point meta=explicit,
] table [
    col sep=comma,
    x=xitem,
    y=yitem,
    meta expr=\thisrow{val},
] {\datatable};

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this question
3  
Take a look at Parametrize shading in table through TikZ, Drawing heatmaps using TikZ, and matlab2tikz imagesc TikZ/pgfplots equivalent for some approaches to similar problems. –  Jake Jan 14 at 14:57
    
Would you consider using a plot? If yes, you can do this with pgfplots. –  Marc van Dongen Jan 14 at 17:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.