5

I have an image of the heatmap, in which each region represents a stage of the process. I want to show few images of process pointing towards heatmap. All these images are stacked vertically and the heatmap is placed next to the stack in vertically center style.

Below is the code snippet-

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric, arrows}
\tikzset{
  box/.style = {draw, rectangle, draw=white},
  to/.style  = {->, >=stealth', shorten >=1pt, thin, draw=orange, fill=orange}
}

\begin{document}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (heatmap) at (0,0,0) {\includegraphics[width=60pt]{example-grid-100x100pt}};
    \begin{scope}[x={(heatmap.south east)},y={(heatmap.north west)}]
        \begin{scope}[x={(heatmap.south east)},y={(heatmap.north west)}]
            \draw (-.5,1.6) node[box] (one) {\includegraphics[width=40pt]{example-image-a}};
            \draw (-.5,0.8) node[box] (two) {\includegraphics[width=40pt]{example-image-b}};
            \draw (-.5,-.0) node[box] (three) {\includegraphics[width=40pt]{example-image-c}};
            \draw (-.5,-.8) node[box] (four) {\includegraphics[width=40pt]{example-image-c}};
                \draw[to] (one)   -- (0.99,0.50);
                \draw[to] (two)   -- (0.70,0.50);
                \draw[to] (three) -- (0.40,0.50);
                \draw[to] (four)  -- (0.10,0.50);
        \end{scope}
    \end{scope}
\end{tikzpicture}
\end{document}

The generated PDF looks like following- screenshot of the generated PDF

It is really difficult to place all these images in the proper place. Hence, I am looking for any better way to achieve the same.

  • if "are stacked vertically" is just a fact an not a restriction, you could also use positioning library to distribute the figures around the heatmap. – Ignasi Apr 16 '18 at 11:43
  • Why two nested scopes? I think one is enough. – Ignasi Apr 16 '18 at 11:43
5

You could use the positioning library of TikZ, see the below = of calls. See PGF manual Section 17.5.3 p229 for more information.

The code below places the first image in the column above left of the heatmap, then all other images are successively placed below the previous one, at a 0.5cm distance

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric, arrows,positioning}
\tikzset{
  box/.style = {draw, rectangle, draw=white},
  to/.style  = {->, >=stealth', shorten >=1pt, thin, draw=orange, fill=orange}
}

\begin{document}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (heatmap) at (0,0,0) {\includegraphics[width=60pt]{example-grid-100x100pt}};
            \node[above left = 1cm of heatmap] (one) {\includegraphics[width=40pt]{example-image-a}};
            \node[below = 0.5cm of one] (two) {\includegraphics[width=40pt]{example-image-b}};
            \node[below = 0.5cm  of two] (three) {\includegraphics[width=40pt]{example-image-c}};
            \node[below = 0.5cm of three] (four) {\includegraphics[width=40pt]{example-image-c}};
            \draw[to] (one)   -- (0.99,0.50);
            \draw[to] (two)   -- (0.70,0.50);
            \draw[to] (three) -- (0.40,0.50);
            \draw[to] (four)  -- (0.10,0.50);
\end{tikzpicture}
\end{document}

EDIT The snippet below shows how to connect one of the boxes to a specific cell in the grid. I added some length definitions to make it a bit easier. And I used the calc library of TikZ for this.

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric, arrows,positioning,calc}
\tikzset{
  box/.style = {draw, rectangle, draw=white},
  to/.style  = {->, >=stealth', shorten >=0pt, thin, draw=orange, fill=orange}
}

\newlength{\gridwidth}
\setlength{\gridwidth}{60pt}
\newlength{\cellwidth}
\setlength{\cellwidth}{6pt}
\begin{document}
\begin{tikzpicture}
            \node[anchor=south west,inner sep=0,outer sep=0pt] (heatmap) at (0,0,0) {\includegraphics[width=\gridwidth]{example-grid-100x100pt}};
            \node[above left = 1cm of heatmap] (one) {\includegraphics[width=40pt]{example-image-a}};
            \draw[to] (one)   -- ($(heatmap.south west)+ (1.5*\cellwidth,0.5*\cellwidth)$);            
\end{tikzpicture}
\end{document}
  • Just one quick question, how do you position the arrow endpoint at a specific location in heatmap image? – Ravi Joshi Apr 16 '18 at 14:06
  • @RaviJoshi, see the edit – BambOo Apr 16 '18 at 17:08

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.