2

I want something like a heat map, where plot points with height 0 appear blue, with height 1 red and everything inbetween I want a fade of colors.

Here is my code:

\documentclass[12pt]{report}    
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

  \begin{tikzpicture}
    \begin{axis}
        \addplot3[red,only marks]
        {e^(-pi * 50^(-2) * (x^2 + y^2))};
    \end{axis}
  \end{tikzpicture}

\end{document}
4
  • 3
    Hello, you already have been asked twice to post a complete minimal working example and not a snippet like you did three times now. Please consider doing this from now on and maybe have a look to this website rules.
    – SebGlav
    Sep 27 at 14:19
  • 2
    @kerf Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for the users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Sep 27 at 14:26
  • 2
    That's much better, but there's lots of information about heat maps in TikZ. Have you tried looking through that?
    – Teepeemm
    Sep 27 at 15:00
  • @Teepeemm I did, but for my case there are unfortunatly not many examples :/
    – kerf
    Sep 27 at 15:57

1 Answer 1

2

red-blue colormap

Code below is slightly modified from pgfplots manual's equivalence for winter. Look at 'surface' or surf for ways to adjust the output further.

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{
  /pgfplots/colormap={redblue}{rgb255=(0,0,255) rgb255=(255,0,0)}
}
\begin{document}

  \begin{tikzpicture}
    \begin{axis}
        \addplot3[surf]
        {e^(-pi * 50^(-2) * (x^2 + y^2))};
    \end{axis}
  \end{tikzpicture}

\end{document}

if you don't want a fading which fills the surface, but only to colour the marks with colours from the colormap, you can use only marks,scatter in place of surf:

marks/scatter rather than surface fill

4
  • Hey, I appreciate your help! My problem is now, that by using \addplot3[only marks] I have a discrete set of plot dots and I want those dots to be colored and not the whole graph of the function
    – kerf
    Sep 27 at 15:55
  • @kerf How is that a fade? Do you mean you want the colours of the points to be the colours they would be if the surface did use a fading? This isn't really my area, so I may just misunderstand the terms involved.
    – cfr
    Sep 27 at 16:07
  • 1
    @kerf If that's a correct interpretation, see edit above. I have to say, the result looks rather strange to me. The marks don't look as if they are in the correct depth order.
    – cfr
    Sep 27 at 16:15
  • 1
    This is exactly what I wanted. Thanks! You are right, this instance looks a little bit weird, but with smaller dots and larger sample size (my actual version) it looks alright :)
    – kerf
    Sep 27 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .