matlab2tikz imagesc TikZ/pgfplots equivalent
You could use a scatter plot with square markers for this. This requires a bit of work to scale the axis and markers so they join exactly, but this can be tucked away in a style
. Then you can simply say
\begin{tikzpicture}
\begin{axis}[
width=8cm,
matrix plot,
colorbar
]
\addplot table [meta=funceval] { ... };
\end{axis}
\end{tikzpicture}
to get
Note that you have to specify the number of rows and columns using the keys matrix rows
and matrix cols
.
Here's the complete code:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{
matrix plot/.style={
axis on top,
clip marker paths=true,
scale only axis,
height=\matrixrows/\matrixcols*\pgfkeysvalueof{/pgfplots/width},
enlarge x limits={rel=0.5/\matrixcols},
enlarge y limits={rel=0.5/\matrixrows},
scatter/use mapped color={draw=mapped color, fill=mapped color},
scatter,
point meta=explicit,
mark=square*,
cycle list={
mark size=0.5*\pgfkeysvalueof{/pgfplots/width}/\matrixcols
}
},
matrix rows/.store in=\matrixrows,
matrix rows=10,
matrix cols/.store in=\matrixcols,
matrix cols=10
}
\begin{tikzpicture}
\begin{axis}[
width=8cm,
matrix plot,
colormap/hot,
colorbar
]
\addplot table [meta=funceval] {
ppm popsize timessolved funceval
0.005 100 30 5.2312e+06
0.105 100 30 1.6282e+06
0.205 100 29 2.0174e+06
0.305 100 30 1.66e+06
0.405 100 28 2.639e+06
0.505 100 24 4.404e+06
0.605 100 16 7.9352e+06
0.705 100 8 1.1446e+07
0.805 100 6 1.2217e+07
0.905 100 9 1.0817e+07
0.005 150 30 8.688e+06
0.105 150 30 2.1773e+06
0.205 150 30 2.2315e+06
0.305 150 30 2.401e+06
0.405 150 30 2.6153e+06
0.505 150 26 5.426e+06
0.605 150 21 8.7765e+06
0.705 150 23 7.0593e+06
0.805 150 16 1.1344e+07
0.905 150 14 1.2771e+07
0.005 200 30 6.6252e+06
0.105 200 30 3.0197e+06
0.205 200 30 2.9699e+06
0.305 200 30 3.1497e+06
0.405 200 30 3.5268e+06
0.505 200 30 3.7531e+06
0.605 200 27 6.1353e+06
0.705 200 24 8.3013e+06
0.805 200 21 1.0925e+07
0.905 200 17 1.4032e+07
0.005 250 30 8.1181e+06
0.105 250 30 3.5341e+06
0.205 250 30 3.8653e+06
0.305 250 30 3.7785e+06
0.405 250 30 4.3767e+06
0.505 250 30 4.3917e+06
0.605 250 29 5.3275e+06
0.705 250 29 4.6693e+06
0.805 250 23 1.0961e+07
0.905 250 25 8.02e+06
0.005 300 30 8.5783e+06
0.105 300 30 4.0582e+06
0.205 300 30 4.263e+06
0.305 300 30 4.692e+06
0.405 300 30 5.1478e+06
0.505 300 30 5.4769e+06
0.605 300 29 6.3917e+06
0.705 300 26 9.4055e+06
0.805 300 26 8.7111e+06
0.905 300 18 1.9458e+07
0.005 350 30 1.0232e+07
0.105 350 30 4.5218e+06
0.205 350 30 4.9123e+06
0.305 350 30 5.3983e+06
0.405 350 30 5.9751e+06
0.505 350 30 6.3135e+06
0.605 350 30 5.7111e+06
0.705 350 30 4.6045e+06
0.805 350 27 8.4856e+06
0.905 350 24 1.2849e+07
0.005 400 30 8.3002e+06
0.105 400 30 5.2684e+06
0.205 400 30 5.5534e+06
0.305 400 30 6.1292e+06
0.405 400 30 6.6702e+06
0.505 400 30 7.2192e+06
0.605 400 30 6.9306e+06
0.705 400 30 5.5206e+06
0.805 400 30 4.0857e+06
0.905 400 29 5.1603e+06
0.005 450 30 1.0286e+07
0.105 450 30 5.8948e+06
0.205 450 30 5.9761e+06
0.305 450 30 6.5749e+06
0.405 450 30 7.6008e+06
0.505 450 30 8.2071e+06
0.605 450 30 7.7313e+06
0.705 450 30 6.0063e+06
0.805 450 29 6.7191e+06
0.905 450 28 7.9783e+06
0.005 500 30 9.0253e+06
0.105 500 30 6.2937e+06
0.205 500 30 6.7477e+06
0.305 500 30 7.3703e+06
0.405 500 30 8.5554e+06
0.505 500 30 8.8726e+06
0.605 500 30 8.4899e+06
0.705 500 30 6.775e+06
0.805 500 30 5.2942e+06
0.905 500 29 6.8066e+06
0.005 550 30 1.1179e+07
0.105 550 30 7.0593e+06
0.205 550 30 7.3797e+06
0.305 550 30 7.7037e+06
0.405 550 30 8.7875e+06
0.505 550 30 9.9175e+06
0.605 550 30 1.0188e+07
0.705 550 30 7.4751e+06
0.805 550 30 5.8577e+06
0.905 550 30 4.4054e+06
};
\end{axis}
\end{tikzpicture}
\end{document}
With the new features matrix plot
and matrix plot*
available in PGFPlots v1.13 Jake's answer can be simplified to the following code. You can find the description in section 4.6.12 on page 164 of the manual.
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=8cm,
enlargelimits=false,
axis on top, % <-- (use with `matrix plot*')
colormap/viridis,
colorbar,
point meta=explicit,
% change me to adjust ``end point'' values used for the colormap
point meta min=0e7,
point meta max=2e7,
% change min and max values to just show that interval in the colorbar
% colorbar style={
% ymin=0.5e7,
% ymax=2.5e7,
% },
]
% \addplot [matrix plot] table [meta=funceval] {
\addplot [matrix plot*] table [meta=funceval] {
ppm popsize timessolved funceval
0.005 100 30 5.2312e+06
0.105 100 30 1.6282e+06
0.205 100 29 2.0174e+06
0.305 100 30 1.66e+06
0.405 100 28 2.639e+06
0.505 100 24 4.404e+06
0.605 100 16 7.9352e+06
0.705 100 8 1.1446e+07
0.805 100 6 1.2217e+07
0.905 100 9 1.0817e+07
0.005 150 30 8.688e+06
0.105 150 30 2.1773e+06
0.205 150 30 2.2315e+06
0.305 150 30 2.401e+06
0.405 150 30 2.6153e+06
0.505 150 26 5.426e+06
0.605 150 21 8.7765e+06
0.705 150 23 7.0593e+06
0.805 150 16 1.1344e+07
0.905 150 14 1.2771e+07
0.005 200 30 6.6252e+06
0.105 200 30 3.0197e+06
0.205 200 30 2.9699e+06
0.305 200 30 3.1497e+06
0.405 200 30 3.5268e+06
0.505 200 30 3.7531e+06
0.605 200 27 6.1353e+06
0.705 200 24 8.3013e+06
0.805 200 21 1.0925e+07
0.905 200 17 1.4032e+07
0.005 250 30 8.1181e+06
0.105 250 30 3.5341e+06
0.205 250 30 3.8653e+06
0.305 250 30 3.7785e+06
0.405 250 30 4.3767e+06
0.505 250 30 4.3917e+06
0.605 250 29 5.3275e+06
0.705 250 29 4.6693e+06
0.805 250 23 1.0961e+07
0.905 250 25 8.02e+06
0.005 300 30 8.5783e+06
0.105 300 30 4.0582e+06
0.205 300 30 4.263e+06
0.305 300 30 4.692e+06
0.405 300 30 5.1478e+06
0.505 300 30 5.4769e+06
0.605 300 29 6.3917e+06
0.705 300 26 9.4055e+06
0.805 300 26 8.7111e+06
0.905 300 18 1.9458e+07
0.005 350 30 1.0232e+07
0.105 350 30 4.5218e+06
0.205 350 30 4.9123e+06
0.305 350 30 5.3983e+06
0.405 350 30 5.9751e+06
0.505 350 30 6.3135e+06
0.605 350 30 5.7111e+06
0.705 350 30 4.6045e+06
0.805 350 27 8.4856e+06
0.905 350 24 1.2849e+07
0.005 400 30 8.3002e+06
0.105 400 30 5.2684e+06
0.205 400 30 5.5534e+06
0.305 400 30 6.1292e+06
0.405 400 30 6.6702e+06
0.505 400 30 7.2192e+06
0.605 400 30 6.9306e+06
0.705 400 30 5.5206e+06
0.805 400 30 4.0857e+06
0.905 400 29 5.1603e+06
0.005 450 30 1.0286e+07
0.105 450 30 5.8948e+06
0.205 450 30 5.9761e+06
0.305 450 30 6.5749e+06
0.405 450 30 7.6008e+06
0.505 450 30 8.2071e+06
0.605 450 30 7.7313e+06
0.705 450 30 6.0063e+06
0.805 450 29 6.7191e+06
0.905 450 28 7.9783e+06
0.005 500 30 9.0253e+06
0.105 500 30 6.2937e+06
0.205 500 30 6.7477e+06
0.305 500 30 7.3703e+06
0.405 500 30 8.5554e+06
0.505 500 30 8.8726e+06
0.605 500 30 8.4899e+06
0.705 500 30 6.775e+06
0.805 500 30 5.2942e+06
0.905 500 29 6.8066e+06
0.005 550 30 1.1179e+07
0.105 550 30 7.0593e+06
0.205 550 30 7.3797e+06
0.305 550 30 7.7037e+06
0.405 550 30 8.7875e+06
0.505 550 30 9.9175e+06
0.605 550 30 1.0188e+07
0.705 550 30 7.4751e+06
0.805 550 30 5.8577e+06
0.905 550 30 4.4054e+06
};
\end{axis}
\end{tikzpicture}
\end{document}