11

I have a huge amount of 2D-coordinates, associated with a value, e.g.:

  x   |   y   | value
27.50   52.15   12.51
61.83   13.32   57.56
36.23   21.83   41.73
40.46   85.67   25.20
...

The data is not tabular and I Want the points between two data-points to be interpolated in some way (which way is not really clear, yet)

I want to preset the data as heatmap like this: heatmap-example

Is there any ready-to-use package for PSTricks or TikZ to do it?

3 Answers3

11

You can also use the pgfplots package, as I show below. I used the same number of data points as Herbert, as well as the default matlab color map. You should compile the following code with LuaLaTeX because it needs a lot of memory. Since it takes a lot of time (about 2 minutes on my PC), it's better to compile it once and then insert the pdf file of your graph as an image.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepackage{xcolor}

\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    colormap/jet,
    colorbar,
    view={0}{90}]
    \addplot3[surf,shader=flat] file {data-map.dat};
\end{axis}
\end{tikzpicture}
\end{document} 

enter image description here

Tom Bombadil
  • 40,123
Red
  • 10,181
  • 2
    Did you use the same data structure as the OP or the on in Herbert's answer? Because I have the same three columns as the OP and I don't get interpolation. – iomartin Apr 04 '14 at 03:59
  • @iomartin It seems to wort if you remove all non-data text from the .data file. But If you have too many data, you get an TeX capacity exceeded error... – AbcAeffchen Dec 09 '15 at 23:21
7

An example with a data set of more than 65000 records (http://tug.org/PSTricks/pst-plot/3D/contourN.data).

\documentclass{article}
\usepackage{pstricks-add}

\begin{document}
\psset{unit=1.5cm}
\begin{pspicture}[showgrid](-3,-3)(3,3)
\pstContour[colored]{contourN.data}
\end{pspicture}

\medskip
\begin{pspicture}[showgrid](-3,-3)(3,3)
\pstContour{contourN.data}
\end{pspicture}%

\end{document}

enter image description here

6

There is tikzDevice for R which will generate TikZ code for a plot created in R. So, if you use R to create your heat map (say, using ggplot2's geom_density2d()), you also get the TikZ code with little effort. There is a learning curve, though.

However, this kind of image should be included as a (perhaps high-resolution) raster image in your document, as the vector version might take a long time to render. So you can create a TikZ version of the plot, compile it to PDF and then convert to PNG at the required resolution/pixel density.

krlmlr
  • 12,530