0

I have this cool looking image from a blog post and I would like to reproduce it using TikZ and pgfplots.

enter image description here

I have found the property point meta but I do not think it's valid in this case. This plot has been generated applying a function $f(t)\in[0,1]$ if $t\in[-1,1]$ and assign a gradient from black ($f(t)=0$) to white ($f(t)=1$).

The squares are $[-1,1]x[-1,1]$.

Any idea aboud how to make any of those three plots?

2
  • 1
    Hi and welcome The shading TikZ library is your friend.
    – AndréC
    Commented Aug 26, 2020 at 7:35
  • @UlrikeFischer Thanks for the hint, now it‘s too late to edit and there is an answer, so I deleted it.
    – TobiBS
    Commented Aug 26, 2020 at 7:47

1 Answer 1

3

You can draw squares with shading inside or you can draw functions and use pgfplots heatmaps to get the shading. This is probably total overkill and way slower than it should be:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
  compat=newest,
  heatmap/.style={
    view={0}{90},
    scale only axis=true,
    domain=-1:1,
    domain y=-1:1,
    width=3cm,
    height=3cm,
    xtick={0},
    xticklabels={},
    ytick={0},
    yticklabels={},
    yticklabel style={overlay},
    grid=major,
    grid style={thick,purple},
    axis line style={purple},
    colormap/blackwhite,
  },
}
\begin{document}
\begin{equation}
  \begin{tikzpicture}[baseline=(C.base)]
    \begin{axis}[heatmap,xlabel={$f(x)$}]
      \node (C) at (axis cs:0,0) {\strut};
      \addplot3 [surf,shader=interp] {exp(-x^2)};
    \end{axis}
  \end{tikzpicture}
  \times
  \begin{tikzpicture}[baseline=(C.base)]
    \begin{axis}[heatmap,xlabel={$f(y)$}]
      \node (C) at (axis cs:0,0) {\strut};
      \addplot3 [surf,shader=interp] {exp(-y^2)};
    \end{axis}
  \end{tikzpicture}
  =
  \begin{tikzpicture}[baseline=(C.base)]
    \begin{axis}[heatmap,xlabel={$f(x) f(y)$}]
      \node (C) at (axis cs:0,0) {\strut};
      \addplot3 [surf,shader=interp] {exp(-x^2-y^2)};
    \end{axis}
  \end{tikzpicture}
\end{equation}
\end{document}

enter image description here

3
  • Uoh, thanks a lot, I did know of that feature. Just one question, will \pgfplotsset{} affect other figures in my document? Commented Aug 26, 2020 at 7:44
  • @AntonioGamizDelgado Yes, but compat=newest is generally something that you want to enable for all figures. Commented Aug 26, 2020 at 8:39
  • @AntonioGamizDelgado You shouldn't use this answer anyway. Have a look in the PGF manual for shadings. That is way faster to typeset, results in a smaller PDF and doesn't have horrible rendering artefacts in some viewers. Commented Aug 26, 2020 at 8:41

You must log in to answer this question.

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