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?

10

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

  • 1
    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 4 '14 at 3: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 9 '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

  • Will there be holes in it if i don't cover the area completely dense with tabular-like coordinates? – user2033412 Sep 18 '13 at 11:52
  • Only the single data record must have three values – user2478 Sep 18 '13 at 12:00
  • Your examples gives me a "! Undefined control sequence. l.12 \pstContour {contourN.data}". Using MikTex 2.9 – user2033412 Sep 18 '13 at 12:18
  • 3
    As I wrote you need the latest pstricks-add.tex. – user2478 Sep 18 '13 at 12:35
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.

  • This makes the learning curve a tad easier -> www.itc.nl/~rossiter/teach/R/LDA.pdf‎ – Forkrul Assail Sep 18 '13 at 13:12
  • @ForkrulAssail: Can't find anything under the URL you provided. 404. – krlmlr Sep 18 '13 at 21:12
  • Sorry, seems they disabled direct linking -> try itc.nl/~rossiter/pubs/list.html then look for Literate Data Analysis. It's about the 3rd one down under R applications. – Forkrul Assail Sep 18 '13 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.