As I wasn't happy with what I could achieve with pgfplots, I tried writing something myself. Basically it's a foreach loop, which computes the color for a specific value and then draws a square. There were some obstacles, as I learned you need \xglobal
to make color definitions global. The result is still far from automatic, but I'm thinking about adding a key-value interface via pgfkeys. Anyway, here's what I have so far:
Code
\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{xifthen}
\begin{document}
\newcommand{\mycolorbar}[6]% height,width,colors,label min,label max,label step
{ \foreach \x [count=\c] in {#3}{ \xdef\numcolo{\c}}
\pgfmathsetmacro{\pieceheight}{#1/(\numcolo-1)}
\xdef\lowcolo{}
\foreach \x [count=\c] in {#3}
{ \ifthenelse{\c = 1}
{}
{ \fill[bottom color=\lowcolo,top color=\x] (0,{(\c-2)*\pieceheight}) rectangle (#2,{(\c-1)*\pieceheight});
}
\xdef\lowcolo{\x}
}
\draw[thick] (0,0) rectangle (#2,#1);
\pgfmathsetmacro{\secondlabel}{#4+#6}
\pgfmathsetmacro{\lastlabel}{#5+0.01}
\pgfkeys{/pgf/number format/.cd,fixed,precision=2}
\foreach \x in {#4,\secondlabel,...,\lastlabel}
{ \draw[thick] (#2,{(\x-#4)/(#5-#4)*#1}) -- ++ (0.15,0) node[right] {\pgfmathprintnumber{\x}};
}
}
\newcommand{\mycolor}[4]% z, min, max, colors
{ \foreach \x [count=\c] in {#4}
{ \xdef\numcolors{\c}
}
\foreach \x [count=\c] in {#4}
{ \ifthenelse{\c > 1}
{ \pgfmathsetmacro{\lowbound}{(\c-2)/(\numcolors-1)*(#3-#2)+#2}
\pgfmathsetmacro{\upbound}{(\c-1)/(\numcolors-1)*(#3-#2)+#2}
\pgfmathtruncatemacro{\thisinterval}{and(#1>=\lowbound,#1<\upbound)?1:0}
\ifthenelse{\thisinterval = 1}
{ \pgfmathtruncatemacro{\myperc}{(#1-\lowbound)/(\upbound-\lowbound)*100}
\pgfmathtruncatemacro{\myinvperc}{100-\myperc}
\xglobal\colorlet{myfillcolor}{rgb:\lowcolor,\myinvperc;\x,\myperc}
}
{}
\pgfmathtruncatemacro{\isbigger}{#1>#3?1:0}
\ifthenelse{\isbigger=1}
{ \xglobal\colorlet{myfillcolor}{\x}
}
{}
}
{ \pgfmathtruncatemacro{\issmaller}{#1<#2?1:0}
\ifthenelse{\issmaller=1}
{ \xglobal\colorlet{myfillcolor}{\x}
}
{}
}
\xdef\lowcolor{\x}
}
}
\begin{tikzpicture}[scale=0.4]
\foreach \z [count=\cz] in {4.21, 4.21, 4.21, 4.21, 4.21, 4.38, 4.38, 4.38, 4.38, 14.74, 14.74, 14.74, 14.74, 14.74, 15.11, 15.11, 16.51, 18.54, 23.02, 23.02, 23.02, 23.02, 23.02, 22.84, 22.84, 24.77, 26.93, 25.18, 25.18, 25.18, 25.18, 25.18, 25.03, 25.03, 25.27, 28.47, 37.71, 37.71, 37.71, 37.71, 37.71, 37.71, 38.51, 40.13, 39.68, 33.62, 33.62, 33.62, 33.62, 33.62, 33.62, 34.02, 34.02, 31.52}
{ \definecolor{myfillcolor}{rgb}{128,128,128}
\mycolor{\z}{0}{45}{blue!50!black, blue!50!gray, blue!50!cyan, green!50!cyan, lime, yellow!50!orange, orange, red, red!50!black}
\fill[myfillcolor] ({mod(\cz-1,9)},{div(\cz-1,9)}) rectangle ++(1,1) node[pos=0.5,black] {};
}
\draw[thick] (0,0) rectangle (9,6);
\foreach \x in {0,...,8}
{ \draw[thick] (\x+0.5,6) -- (\x+0.5,5.7);
\draw[thick] (\x+0.5,0.3) -- (\x+0.5,0) node[below] {\tiny\x};
}
\foreach \y [count=\c] in {0,25,33,50,66,75}
{ \draw[thick] (9,\c-0.5) -- (8.7,\c-0.5);
\draw[thick] (0.3,\c-0.5) -- (0,\c-0.5) node[left] {\tiny\y};
}
\node[below] at (4.5,-0.5) {first raster};
\begin{scope}[shift={(11,0)}]
\foreach \z [count=\cz] in {1,...,54}
{ \definecolor{myfillcolor}{rgb}{128,128,128}
\pgfmathsetmacro{\zr}{rnd*45}
\mycolor{\zr}{0}{45}{blue!50!black, blue!50!gray, blue!50!cyan, green!50!cyan, lime, yellow!50!orange, orange, red, red!50!black}
\fill[myfillcolor] ({mod(\cz-1,9)},{div(\cz-1,9)}) rectangle ++(1,1) node[pos=0.5,black] {};
}
\draw[thick] (0,0) rectangle (9,6);
\foreach \x in {0,...,8}
{ \draw[thick] (\x+0.5,6) -- (\x+0.5,5.7);
\draw[thick] (\x+0.5,0.3) -- (\x+0.5,0) node[below] {\tiny\x};
}
\foreach \y [count=\c] in {0,25,33,50,66,75}
{ \draw[thick] (9,\c-0.5) -- (8.7,\c-0.5);
\draw[thick] (0.3,\c-0.5) -- (0,\c-0.5) node[left] {\tiny\y};
}
\node[below] at (4.5,-0.5) {chaos};
\end{scope}
\begin{scope}[shift={(0,-8)}]
\foreach \z [count=\cz] in {1,...,54}
{ \definecolor{myfillcolor}{rgb}{128,128,128}
\pgfmathsetmacro{\zr}{(mod(\cz-1,9)+div(\cz-1,9))*3}
\mycolor{\zr}{0}{45}{blue!50!black, blue!50!gray, blue!50!cyan, green!50!cyan, lime, yellow!50!orange, orange, red, red!50!black}
\fill[myfillcolor] ({mod(\cz-1,9)},{div(\cz-1,9)}) rectangle ++(1,1) node[pos=0.5,black] {};
}
\draw[thick] (0,0) rectangle (9,6);
\foreach \x in {0,...,8}
{ \draw[thick] (\x+0.5,6) -- (\x+0.5,5.7);
\draw[thick] (\x+0.5,0.3) -- (\x+0.5,0) node[below] {\tiny\x};
}
\foreach \y [count=\c] in {0,25,33,50,66,75}
{ \draw[thick] (9,\c-0.5) -- (8.7,\c-0.5);
\draw[thick] (0.3,\c-0.5) -- (0,\c-0.5) node[left] {\tiny\y};
}
\node[below] at (4.5,-0.5) {gradient};
\end{scope}
\begin{scope}[shift={(11,-8)}]
\foreach \z [count=\cz] in {1,...,54}
{ \definecolor{myfillcolor}{rgb}{128,128,128}
\pgfmathsetmacro{\zr}{pow(mod(\cz-1,9),2)+pow(div(\cz-1,9),2)-11}
\mycolor{\zr}{0}{45}{blue!50!black, blue!50!gray, blue!50!cyan, green!50!cyan, lime, yellow!50!orange, orange, red, red!50!black}
\fill[myfillcolor] ({mod(\cz-1,9)},{div(\cz-1,9)}) rectangle ++(1,1) node[pos=0.5,black] {};
}
\draw[thick] (0,0) rectangle (9,6);
\foreach \x in {0,...,8}
{ \draw[thick] (\x+0.5,6) -- (\x+0.5,5.7);
\draw[thick] (\x+0.5,0.3) -- (\x+0.5,0) node[below] {\tiny\x};
}
\foreach \y [count=\c] in {0,25,33,50,66,75}
{ \draw[thick] (9,\c-0.5) -- (8.7,\c-0.5);
\draw[thick] (0.3,\c-0.5) -- (0,\c-0.5) node[left] {\tiny\y};
}
\node[below] at (4.5,-0.5) {floor \& roof};
\end{scope}
\begin{scope}[shift={(21,-8)}]
\mycolorbar{14}{1}{blue!50!black, blue!50!gray, blue!50!cyan, green!50!cyan, lime, yellow!50!orange, orange, red, red!50!black}{0}{45}{5}
\end{scope}
\end{tikzpicture}
\end{document}
Output

pgfplots
. Therefore it would be helpful to have the tabular values in atxt
file. – Henri Menke Sep 19 '13 at 15:55tex
file. I don't see any possibility for this using the backend route. – BartV Sep 23 '13 at 10:55